#include <bits/stdc++.h>
using namespace std;
int n, m, k;
pair<int, int> a[111111];
int d[111111];
int f[111111];
int s[111111];
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  return a.second < b.second;
}
const int mod = 1000000007;
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = 0; (i) < (m); ++(i)) {
    scanf("%d%d", &a[i].first, &a[i].second);
    d[i] = a[i].second;
  }
  d[m] = 0;
  d[m + 1] = n;
  sort(d, d + m + 2);
  k = unique(d, d + m + 2) - d;
  sort(a, a + m, cmp);
  f[0] = 1;
  s[0] = 1;
  for (int i = 0; i < m; ++i) {
    int pos = lower_bound(d, d + k, a[i].first) - d;
    int our = lower_bound(d, d + k, a[i].second) - d;
    if (our) {
      f[our] += s[our - 1];
      if (f[our] >= mod) f[our] -= mod;
    }
    if (pos) {
      f[our] = f[our] + mod - s[pos - 1];
      if (f[our] >= mod) f[our] -= mod;
    }
    if (i == m - 1 || a[i + 1].second != a[i].second) {
      s[our] = s[our - 1] + f[our];
      if (s[our] >= mod) s[our] -= mod;
    }
  }
  cout << f[k - 1] << endl;
}
