#include <bits/stdc++.h>
using namespace std;
int comp(pair<int, int> a, pair<int, int> b) {
  if (a.second < b.second)
    return 1;
  else
    return 0;
}
long long int arr[100001];
int main() {
  int n, m, count, l, r, c = 1000000007, i, j;
  cin >> n >> m;
  if (m == 0) {
    cout << 0;
    return 0;
  }
  vector<pair<int, int> > vec;
  map<int, int> map1;
  map<int, int>::iterator it;
  map<int, int>::reverse_iterator rit, rit1;
  ;
  for (i = 1; i <= m; i++) {
    cin >> l >> r;
    vec.push_back(pair<int, int>(l, r));
  }
  sort(vec.begin(), vec.end(), comp);
  map1[vec[0].second] = 1;
  count = 2;
  for (i = 1; i < vec.size(); i++) {
    if (vec[i].second != vec[i - 1].second) {
      map1[vec[i].second] = count;
      count++;
    }
  }
  map1[0] = 0;
  arr[0] = 1;
  for (i = 0; i < vec.size(); i++) {
    if (vec[i].first == 0)
      arr[map1[vec[i].second]] =
          (arr[map1[vec[i].second]] + arr[map1[vec[i].second] - 1]) % c;
    else {
      it = map1.lower_bound(vec[i].first);
      int temp = arr[map1[vec[i].second]];
      arr[map1[vec[i].second]] =
          ((long long int)arr[map1[vec[i].second]] +
           arr[map1[vec[i].second] - 1] - arr[it->second - 1]) %
          c;
      if (arr[map1[vec[i].second]] <= 0) arr[map1[vec[i].second]] += c;
    }
    if (i > 0 && vec[i].second != vec[i - 1].second)
      arr[map1[vec[i].second]] = (long long int)(arr[map1[vec[i].second]] +
                                                 arr[map1[vec[i].second] - 1]) %
                                 c;
    else if (i == 0)
      arr[map1[vec[i].second]] = (long long int)(arr[map1[vec[i].second]] +
                                                 arr[map1[vec[i].second] - 1]) %
                                 c;
  }
  rit = map1.rbegin();
  rit++;
  rit1 = map1.rbegin();
  if (rit1->first != n)
    cout << 0;
  else if (arr[rit1->second] < arr[rit->second])
    cout << (arr[rit1->second] - arr[rit->second]) + c;
  else if (arr[rit1->second] >= arr[rit->second])
    cout << arr[rit1->second] - arr[rit->second];
}
