#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> hozon;
  vector<pair<int, int> > ending;
  for (int a = 0; a < m; a++) {
    int p, q;
    cin >> p >> q;
    ending.push_back(make_pair(q, p));
    hozon.push_back(q);
  }
  sort(ending.begin(), ending.end());
  sort(hozon.begin(), hozon.end());
  int zero_to_sum[m + 1];
  int count[m + 1];
  zero_to_sum[0] = 0;
  for (int a = 0; a < m; a++) {
    int p, q;
    p = ending[a].second;
    q = ending[a].first;
    int start = lower_bound(hozon.begin(), hozon.end(), p) - hozon.begin();
    int goal = lower_bound(hozon.begin(), hozon.end(), q) - hozon.begin();
    zero_to_sum[a + 1] = zero_to_sum[a];
    count[a] = 0;
    if (start < goal) count[a] += zero_to_sum[goal] - zero_to_sum[start];
    if (p == 0) count[a]++;
    count[a] += 1000000007;
    count[a] %= 1000000007;
    zero_to_sum[a + 1] += count[a];
    zero_to_sum[a + 1] %= 1000000007;
  }
  int Ans = 0;
  for (int a = 0; a < m; a++) {
    if (ending[a].first == n) Ans += count[a], Ans %= 1000000007;
  }
  cout << Ans << endl;
  return 0;
}
