5
92332150 92332151
92332156 92332157
92332157 92332158
92332150 92332151
92332152 92332153
 50
966 988
924 932
872 923
890 928
830 926
832 965
763 934
809 942
731 905
707 859
674 820
635 781
660 786
718 865
666 800
672 814
750 874
692 819
622 816
639 882
693 886
630 814
657 874
706 890
659 852
633 808
556 787
493 737
568 812
631 860
558 816
558 873
510 840
472 825
551 852
628 908
643 935
669 961
655 899
687 936
651 916
605 872
551 846
526 784
552 818
562 894
619 922
631 973
690 984
665 946
 30
1 2
2 3
3 4
4 5
5 6
1 2
2 3
3 4
4 5
5 6
1 2
2 3
3 4
4 5
5 6
1 2
2 3
3 4
4 5
5 6
1 2
2 3
3 4
4 5
5 6
1 2
2 3
3 4
4 5
5 6
 50
467 688
497 698
433 623
402 554
357 489
402 498
439 565
417 492
390 460
330 448
360 474
343 408
382 413
421 473
451 500
402 421
363 408
386 433
406 461
455 491
519 519
503 503
470 486
503 566
580 641
608 711
658 757
654 721
662 796
714 840
677 830
735 841
775 912
839 930
902 996
873 986
908 1000
849 922
921 993
891 984
950 1000
1000 1000
1000 1000
977 977
1000 1000
1000 1000
1000 1000
991 995
1000 1000
1000 1000
 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
1 30
 50
857 893
915 922
836 851
915 915
923 983
883 921
807 903
757 858
789 938
740 893
765 914
837 951
857 984
881 1000
930 1000
997 1000
1000 1000
1000 1000
956 956
999 1000
1000 1000
964 964
1000 1000
936 983
943 1000
943 1000
902 986
877 938
887 944
887 962
915 969
915 988
910 956
929 1000
983 1000
934 998
945 1000
963 1000
926 926
938 960
897 945
882 882
907 953
894 932
888 888
968 968
959 959
1000 1000
1000 1000
1000 1000
 50
692 746
680 694
609 677
674 743
647 695
703 763
701 701
640 640
616 616
560 613
559 599
501 573
483 548
450 541
407 541
479 552
457 481
452 452
396 428
355 368
291 318
256 297
255 255
184 184
118 126
70 70
29 29
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
77 77
45 45
9 9
1 1
1 1
77 77
 50
255 364
200 358
123 354
80 285
79 256
84 288
25 231
22 210
1 138
1 72
1 29
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
78 78
16 56
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
81 81
68 68
23 39
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
75 75
 50
472 604
507 626
503 587
467 546
514 571
473 520
437 461
485 485
451 474
417 461
389 459
372 397
416 429
378 378
307 371
284 322
246 279
179 207
124 172
67 92
119 119
76 91
1 42
1 1
23 39
1 33
1 24
1 18
51 81
1 76
22 120
1 58
80 96
6 37
1 1
1 1
9 55
1 7
15 62
1 2
1 1
38 68
1 34
71 97
119 171
102 169
75 158
96 228
26 227
43 239
 1
1000000000 1000000000
 50
543 935
572 940
526 874
553 946
534 874
594 951
646 960
595 917
606 922
648 979
652 1000
622 947
698 984
764 990
815 1000
862 1000
894 1000
910 1000
957 1000
995 1000
1000 1000
1000 1000
1000 1000
1000 1000
987 987
953 953
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
943 943
987 992
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
982 982
943 943
994 1000
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
964 964
 5
55073405 55073406
55073402 55073403
55073402 55073403
55073404 55073406
55073409 55073410
 30
30 30
29 29
28 28
27 27
26 26
25 25
24 24
23 23
22 22
21 21
20 20
19 19
18 18
17 17
16 16
15 15
14 14
13 13
12 12
11 11
10 10
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
 50
82 128
67 78
30 34
1 34
1 7
1 4
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
8 78
1 40
1 24
1 1
1 1
1 1
1 1
1 1
1 1
67 67
29 29
1 6
3 56
25 125
1 70
1 5
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
6 66
1 1
1 1
17 17
1 1
44 44
1 1
 20
1 2
4 13
17 18
24 28
16 34
5 25
1 23
8 26
27 36
1 27
3 9
15 29
8 16
9 28
13 34
7 11
3 7
12 40
20 28
10 33

3 41 6 35 30 25 5 8 18 1 23 4 1 12 14
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, t = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') t = -1;
    c = getchar();
  }
  while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
  return s * t;
}
const int N = 3e5 + 5, inf = 1e9 + 7;
struct node {
  int sz, l, r, v, tv, key;
  node() { sz = 1; }
} t[N];
int rt;
inline int R() { return ((rand() << 8) ^ (rand() << 4) ^ rand()); }
inline void A(int x, int d) { t[x].v += d, t[x].tv += d; }
inline void down(int x) {
  if (t[x].tv) A(t[x].l, t[x].tv), A(t[x].r, t[x].tv), t[x].tv = 0;
}
inline void up(int x) { t[x].sz = t[t[x].l].sz + t[t[x].r].sz + 1; }
inline int merge(int x, int y) {
  if (!x || !y) return x | y;
  down(x), down(y);
  if (t[x].key > t[y].key) {
    t[x].r = merge(t[x].r, y);
    return up(x), x;
  } else {
    t[y].l = merge(x, t[y].l);
    return up(y), y;
  }
}
inline pair<int, int> split(int x, int y) {
  if (!y) return make_pair(0, x);
  down(x);
  if (t[t[x].l].sz >= y) {
    pair<int, int> cur = split(t[x].l, y);
    t[x].l = cur.second, up(x);
    return make_pair(cur.first, x);
  }
  pair<int, int> cur = split(t[x].r, y - t[t[x].l].sz - 1);
  t[x].r = cur.first, up(x);
  return make_pair(x, cur.second);
}
inline pair<int, int> Split(int x, int y) {
  int sz = 0, j = x;
  while (j) {
    if (t[j].v < y)
      sz += t[t[j].l].sz + 1, j = t[j].r;
    else
      j = t[j].l;
  }
  return split(x, sz);
}
inline void Out(int x) {
  if (t[x].l) Out(t[x].l);
  cout << "O " << x << " " << t[x].v << " " << t[x].sz << " " << t[x].key
       << endl;
  if (t[x].r) Out(t[x].r);
}
int main() {
  int n = read();
  t[0].sz = 0;
  t[1].key = R(), t[1].v = 0, rt = merge(rt, 1);
  for (register int i = 2; i <= n + 1; i++)
    t[i].key = R(), t[i].v = inf, rt = merge(rt, i);
  for (register int i = 1; i <= n; i++) {
    int l = read(), r = read(), x;
    pair<int, int> a = Split(rt, l);
    pair<int, int> b = Split(a.second, r);
    pair<int, int> c = split(b.second, 1);
    x = t[a.first].sz;
    a = split(a.first, x - 1);
    t[c.first].v = t[a.second].v;
    t[a.second].v = l;
    A(b.first, 1);
    rt = merge(a.first, c.first);
    rt = merge(rt, a.second);
    rt = merge(rt, b.first);
    rt = merge(rt, c.second);
  }
  pair<int, int> a = Split(rt, inf);
  cout << t[a.first].sz - 1 << endl;
  return 0;
}
