#include <bits/stdc++.h>
using namespace std;
const int N = 100010 * 2;
const int Mod = 1000000007;
int dp[N];
vector<pair<int, int> > bus;
vector<int> desc;
vector<int> adj[N];
int c[N];
int Modify(int pos, int num) {
  for (; pos <= N; pos += (pos & (-pos))) {
    c[pos] += num;
    c[pos] %= Mod;
  }
}
int Getsum(int end) {
  if (end == 0) return 0;
  int sum = 0;
  for (; end > 0; end -= (end & (-end))) {
    sum += c[end];
    sum %= Mod;
  }
  return sum;
}
void init() {
  for (int i = 0; i < N; i++) adj[i].clear();
  desc.clear();
  bus.clear();
  memset(c, 0, sizeof(c));
}
int DP(int now) {
  if (dp[now] != -1) return dp[now];
  if (now == 1) return dp[now] = 1;
  int ans = 0;
  for (int i = 0; i < adj[now].size(); i++) {
    ans += Getsum(now - 1) - Getsum(bus[adj[now][i]].first - 1);
    ans = (ans % Mod + Mod) % Mod;
  }
  return dp[now] = ans;
}
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m) == 2) {
    init();
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      u++;
      v++;
      desc.push_back(u);
      desc.push_back(v);
      bus.push_back(make_pair(u, v));
    }
    sort(desc.begin(), desc.end());
    desc.erase(unique(desc.begin(), desc.end()), desc.end());
    for (int i = 0; i < bus.size(); i++) {
      bus[i].first = lower_bound(desc.begin(), desc.end(), bus[i].first) -
                     desc.begin() + 1;
      bus[i].second = lower_bound(desc.begin(), desc.end(), bus[i].second) -
                      desc.begin() + 1;
      adj[bus[i].second].push_back(i);
    }
    if (m == 0 || desc[0] != 1 || *desc.rbegin() != n + 1) {
      printf("0\n");
      continue;
    }
    int final = lower_bound(desc.begin(), desc.end(), n + 1) - desc.begin() + 1;
    memset(dp, -1, sizeof(dp));
    for (int i = 1; i <= final; i++) {
      Modify(i, DP(i));
    }
    printf("%d\n", DP(final));
  }
  return 0;
}
