#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<int> adj[N];
long long dyn[N], sum[N];
const int mod = 1000000007;
int rate[N];
long long dp(int);
struct node {
  int x, y;
  void fun(int a, int b) {
    x = a;
    y = b;
  }
} pnt[N];
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    puts("0");
    return 0;
  }
  bool flag = 0;
  set<int> scatter;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    pnt[i].fun(a, b);
    if (min(a, b) == 0) flag = 1;
    scatter.insert(a);
    scatter.insert(b);
  }
  if (!flag) {
    puts("0");
    return 0;
  }
  int cnt = 0;
  set<int>::iterator it;
  for (it = scatter.begin(); it != scatter.end(); it++) rate[cnt++] = (*it);
  for (int i = 0; i < m; i++) {
    int a = lower_bound(rate, rate + cnt, pnt[i].x) - rate;
    int b = lower_bound(rate, rate + cnt, pnt[i].y) - rate;
    adj[b].push_back(a);
  }
  int ind = lower_bound(rate, rate + cnt, n) - rate;
  memset(dyn, 0, sizeof(dyn));
  dyn[0] = 1;
  sum[0] = 1;
  for (int i = 1; i <= ind; i++) {
    for (int j = 0; j < (int)adj[i].size(); j++) {
      dyn[i] = (dyn[i] + sum[i - 1]) % mod;
      int tmp = adj[i][j] - 1;
      if (tmp >= 0) dyn[i] = (dyn[i] - sum[tmp] + mod) % mod;
    }
    sum[i] = (dyn[i] + sum[i - 1]) % mod;
  }
  printf("%d\n", dyn[ind]);
  return 0;
}
