#include <bits/stdc++.h>
using namespace std;
struct mar {
  int s, t;
};
bool cmp(mar a, mar b) { return (a.t < b.t); }
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0)
    cout << 0 << endl;
  else {
    mar* a = new mar[m];
    for (int i = 0; i < m; ++i) scanf("%d%d", &a[i].s, &a[i].t);
    sort(a, a + m, cmp);
    vector<int> c(m, 0);
    vector<int> d(m + 1, 0);
    c[0] = (a[0].s == 0);
    d[1] = c[0];
    for (int k = 1; k < m; k++) {
      int l = 0, r = k - 1;
      int cs, ce;
      while (l < r) {
        int mr = (l + r) / 2;
        if (a[mr].t < a[k].s)
          l = mr + 1;
        else
          r = mr;
      }
      if (a[l].t < a[k].s)
        cs = l + 1;
      else
        cs = l;
      l = 0, r = k - 1;
      while (l < r) {
        int mr = (l + r) / 2;
        if (a[mr].t < a[k].t)
          l = mr + 1;
        else
          r = mr;
      }
      if (a[l].t < a[k].t)
        ce = l;
      else
        ce = l - 1;
      long long sum = (a[k].s == 0) + d[ce + 1] - d[cs];
      if (sum < 0) sum += 1000000007;
      c[k] = sum % 1000000007;
      d[k + 1] = (d[k] + c[k]) % 1000000007;
    }
    long long sum = 0;
    for (int k = m - 1; (k >= 0 && a[k].t == n);) {
      sum += c[k];
      k--;
    }
    cout << sum % 1000000007 << endl;
  }
  return 0;
}
