#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int N = 201000;
struct San {
  int a[N], n;
  void init() { n = 0; }
  void push(int x) { a[n++] = x; }
  void doit() {
    sort(a, a + n);
    n = unique(a, a + n) - a;
  }
  int operator[](int x) { return lower_bound(a, a + n, x) - a; }
} ss;
int n, m, C[N];
pair<int, int> bus[N];
inline void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
void treeAdd(int p, int dt) {
  for (int i = p; i < ss.n; i += i & -i) add(C[i], dt);
}
int treeSum(int p) {
  int ret = 0;
  for (int i = p; i > 0; i -= i & -i) add(ret, C[i]);
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  ss.init();
  ss.push(-1);
  ss.push(0);
  ss.push(n);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &bus[i].second, &bus[i].first);
    ss.push(bus[i].first);
    ss.push(bus[i].second);
  }
  ss.doit();
  treeAdd(1, 1);
  sort(bus, bus + m);
  for (int i = 0; i < m; i++) {
    int l = ss[bus[i].second];
    int r = ss[bus[i].first];
    int dt = 0;
    add(dt, treeSum(r - 1));
    add(dt, MOD - treeSum(l - 1));
    treeAdd(r, dt);
  }
  int ans = treeSum(ss[n]);
  add(ans, MOD - treeSum(ss[n] - 1));
  printf("%d\n", ans);
  return 0;
}
