#include<bits/stdc++.h>
using namespace std;
int n,a[3005], b[3005],k=0;
int main()
{
//freopen("1452.in","r",stdin);
//freopen("1452.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
}
for(int i=2;i<=n;i++)
{
if(a[i]+b[i]>8)
{
k+=a[i]+b[i]-8;
}
}
cout<<"-"<<k;
return 0;
}