#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int n, dp[maxn][15];
int main()
{
while (scanf("%d", &n) == 1 && n) {
memset(dp, 0, sizeof(dp));
int t = 0;
for (int i = 0; i < n; i++) {
int a, b; scanf("%d %d", &a, &b);
dp[b][a + 1]++;
t = max(t, b);
}
for (int i = t; i >= 0; i--) {
for (int j = 1; j <= 11; j++) {
dp[i][j] += max(dp[i + 1][j], max(dp[i + 1][j + 1], dp[i + 1][j - 1]));
}
}
printf("%d\n", dp[0][6]);
}
return 0;
}