#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> T;
vector<pair<int, int>> res;
int main()
{
int week = 7;
while (week--)
{
int t1, t2; scanf("%d%d", &t1, &t2);
T.push_back({ t1, t2 });
}
for (int i = 0; i < 7; i++)
{
int t = T[i].first + T[i].second;
if ( t > 8) res.push_back({ i + 1, t });
}
sort(res.begin(), res.end());
if (res.empty()) printf("0\n");
else printf("%d\n", res[0].first);
return 0;
}