#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const double EPS = 1e-9;
const int MOD = 1000000007;
typedef struct {
  int first, second;
} lho;
lho tmp;
bool operator<(const lho &a, const lho &b) { return a.second < b.second; }
int n, m;
int dp[200005];
lho seg[100005];
int aw[100005];
int ak[100005];
int sum[100005];
int f(int p) {
  int &ret = dp[p];
  if (ret != -1) return ret;
  ret = 0;
  if (seg[p].first == 0) ret = 1;
  if (ak[p] - 1 >= 0) ret = (ret + sum[ak[p] - 1]) % MOD;
  if (aw[p] - 1 >= 0) ret = (ret + MOD - sum[aw[p] - 1]) % MOD;
  return ret;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d %d", &seg[i].first, &seg[i].second);
  sort(seg, seg + m);
  int a = 0;
  int b = 0;
  for (int i = 0; i < m; i++) {
    while (seg[b].second < seg[i].second) b++;
    ak[i] = b;
  }
  for (int i = 0; i < m; i++) {
    int lo = 0;
    int hi = i;
    while (lo <= hi) {
      int pvt = (lo + hi) / 2;
      if (seg[pvt].second >= seg[i].first)
        hi = pvt - 1;
      else
        lo = pvt + 1;
    }
    aw[i] = lo;
  }
  memset(dp, -1, sizeof(dp));
  sum[0] = f(0);
  for (int i = 1; i < m; i++) sum[i] = (sum[i - 1] + f(i)) % MOD;
  int ans = 0;
  for (int i = 0; i < m; i++)
    if (seg[i].second == n) ans = (ans + f(i)) % MOD;
  printf("%d\n", ans);
  return 0;
}
