#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100010];
pair<int, pair<int, int> > s[200010];
map<int, int> res;
const long long mod = (long long)1e9 + 7;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &a[i].first, &a[i].second);
  for (int i = 0; i < m; i++) {
    s[2 * i] = make_pair(a[i].first, make_pair(0, a[i].second));
    s[2 * i + 1] = make_pair(a[i].second, make_pair(1, a[i].second));
  }
  sort(s, s + 2 * m);
  int sum = 0;
  res.insert(make_pair(n, 1));
  for (int i = 2 * m - 1; i >= 0;) {
    if (s[i].first < n) res.insert(make_pair(s[i].first, sum));
    int j = i;
    long long dsum = 0;
    while (j >= 0 && s[i].first == s[j].first) {
      if (s[j].second.first == 0)
        dsum += mod - res[s[j].second.second];
      else
        dsum += res[s[i].first];
      j--;
    }
    i = j;
    sum = (sum + dsum) % mod;
  }
  printf("%d", res[0]);
  return 0;
}
