/*
  Marek p2004a Rusinowski
  II Etap XVIII OI zadanie Temperatura
*/

#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define od second
#define wys first

pair<int, int> t[2000001];
pair<int, int> *begin = t + 2000000;
pair<int, int> *end = begin - 1;

int main() {
  int n, a, b, ab, bb, res = 0;
  scanf("%d", &n);
  scanf("%d %d", &a, &b);
  ab = a; bb = b;
  begin->wys = a;
  begin->od = 0;
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &a, &b);
    if (b < begin->wys) { // góra sie zmnijesza wiec coś może odpaść
      res = max(res, i - begin->od);
      while (b < begin->wys && begin != end) {
        --begin;
      }
    }
    if (a < ab) { // dół idzie w dół więc dorzucamy
      end->od = i;
      end->wys = a;
      --end;
    } else if (a > ab) {  // duł idzie w góre wiec podnoscimy do góry i ucinamy
      (end + 1)->wys = a;
      while (((end + 2)->wys <= a) && ((end + 1) < begin)) {
        (end + 2)->wys = a;
        ++end;
      }
    }
    ab = a; bb = b;
  } 
  res = max(res, n - begin->od);
  printf("%dn", res);
  return 0;
}

