#include<bits/stdc++.h>
using namespace std;typedeflonglong ll;typedeflongdouble lf;typedefunsignedlonglong ull;typedef pair<ll,int>P;constint inf =0x7f7f7f7f;const ll INF =1e16;constint N =1e4+10;const ull base =131;const ll mod =1e9+7;constdouble PI =acos(-1.0);constdouble eps =1e-4;inlineintread(){
int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';ch=getchar();}return x*f;}inline string readstring(){
string str;char s=getchar();while(s==' '||s=='\n'||s=='\r'){
s=getchar();}while(s!=' '&&s!='\n'&&s!='\r'){
str+=s;s=getchar();}return str;}intrandom(int n){
return(int)(rand()*rand())%n;}voidwritestring(string s){
int n = s.size();for(int i =0;i < n;i++){
printf("%c",s[i]);}}
ll fast_power(ll a,ll p){
ll ans =1;while(p){
if(p&1) ans =(ans*a)%mod;
p >>=1;
a =(a*a)%mod;}return ans;}
map<int,vector<int>>g;
vector<int>a[10];intmain(){
//srand((unsigned)time(NULL));//freopen( "out.txt","w",stdout);int n =read();for(int i =1;i <= n;i++){
int p =read(),t =read();
g[t].push_back(p);}int last =0;int ans =0;for(auto it = g.begin();it != g.end();it++){
int x =(it->first)-last,flag =1;while(x--&& flag){
flag =0;for(int i =1;i <=6;i++){
for(int j =0;j < a[i].size();j++){
a[i][j]++;
flag =1;if(a[i][j]==61){
a[i].clear();
ans++;}}}}
vector<int>b = it->second;for(int i =0;i < b.size();i++){
a[b[i]].push_back(1);}
last = it->first;}for(int i =1;i <=6;i++){
if(a[i].size()) ans++;}printf("%d\n",ans);return0;}