#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3fLL;
const long long N = 2e5 + 5;
const long long MOD = 1e9 + 7;
struct BIT {
  long long n;
  vector<long long> ft;
  BIT(long long n) : n(n), ft(n) {}
  long long add(long long x, long long y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
  }
  long long sub(long long x, long long y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
  }
  void upd(long long i, long long x) {
    for (; i < n; i |= i + 1) ft[i] = add(ft[i], x);
  }
  long long get(long long i) {
    long long ans = 0;
    for (; i >= 0; i = (i & (i + 1)) - 1) ans = add(ans, ft[i]);
    return ans;
  }
  long long get_range(long long l, long long r) {
    return sub(get(r), get(l - 1));
  }
  void upd_range(long long l, long long r, long long x) {
    upd(l, x);
    upd(r + 1, -x);
  }
};
long long s[N], t[N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  BIT obj(N);
  vector<long long> a;
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> t[i];
    a.push_back(s[i]);
    a.push_back(t[i]);
  }
  a.push_back(0);
  a.push_back(n);
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  vector<pair<long long, long long>> seg;
  for (long long i = 0; i < m; i++) {
    s[i] = lower_bound(a.begin(), a.end(), s[i]) - a.begin();
    t[i] = lower_bound(a.begin(), a.end(), t[i]) - a.begin();
    seg.emplace_back(t[i], s[i]);
  }
  sort(seg.begin(), seg.end());
  obj.upd(0, 1);
  for (long long i = 0; i < m; i++) {
    obj.upd(seg[i].first, obj.get_range(seg[i].second, seg[i].first - 1));
  }
  cout << obj.get_range(a.size() - 1, a.size() - 1);
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they follow from Gerald's home. The bus stop by Gerald's home has number 0 and the bus stop by the school has number n.

There are m buses running between the house and the school: the i-th bus goes from stop si to ti (si < ti), visiting all the intermediate stops in the order in which they follow on the segment. Besides, Gerald's no idiot and he wouldn't get off the bus until it is still possible to ride on it closer to the school (obviously, getting off would be completely pointless). In other words, Gerald can get on the i-th bus on any stop numbered from si to ti - 1 inclusive, but he can get off the i-th bus only on the bus stop ti.

Gerald can't walk between the bus stops and he also can't move in the direction from the school to the house.

Gerald wants to know how many ways he has to get from home to school. Tell him this number. Two ways are considered different if Gerald crosses some segment between the stops on different buses. As the number of ways can be too much, find the remainder of a division of this number by 1000000007 (109 + 7).

Input

The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers si, ti. They are the numbers of starting stops and end stops of the buses (0 ≤ si < ti ≤ n).

Output

Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).

Examples

Input

2 2
0 1
1 2


Output

1


Input

3 2
0 1
1 2


Output

0


Input

5 5
0 1
0 2
0 3
0 4
0 5


Output

16

Note

The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two.

In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0.

In the third test Gerald can either get or not on any of the first four buses to get closer to the school. Thus, the correct answer is 24 = 16.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3fLL;
const long long N = 2e5 + 5;
const long long MOD = 1e9 + 7;
struct BIT {
  long long n;
  vector<long long> ft;
  BIT(long long n) : n(n), ft(n) {}
  long long add(long long x, long long y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
  }
  long long sub(long long x, long long y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
  }
  void upd(long long i, long long x) {
    for (; i < n; i |= i + 1) ft[i] = add(ft[i], x);
  }
  long long get(long long i) {
    long long ans = 0;
    for (; i >= 0; i = (i & (i + 1)) - 1) ans = add(ans, ft[i]);
    return ans;
  }
  long long get_range(long long l, long long r) {
    return sub(get(r), get(l - 1));
  }
  void upd_range(long long l, long long r, long long x) {
    upd(l, x);
    upd(r + 1, -x);
  }
};
long long s[N], t[N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  BIT obj(N);
  vector<long long> a;
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> t[i];
    a.push_back(s[i]);
    a.push_back(t[i]);
  }
  a.push_back(0);
  a.push_back(n);
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  vector<pair<long long, long long>> seg;
  for (long long i = 0; i < m; i++) {
    s[i] = lower_bound(a.begin(), a.end(), s[i]) - a.begin();
    t[i] = lower_bound(a.begin(), a.end(), t[i]) - a.begin();
    seg.emplace_back(t[i], s[i]);
  }
  sort(seg.begin(), seg.end());
  obj.upd(0, 1);
  for (long long i = 0; i < m; i++) {
    obj.upd(seg[i].first, obj.get_range(seg[i].second, seg[i].first - 1));
  }
  cout << obj.get_range(a.size() - 1, a.size() - 1);
  return 0;
}

```