#include <bits/stdc++.h>
using namespace std;
struct P {
  int s, e;
} bus[110000];
struct Pp {
  int left, right;
  long long val;
} segtree[1000000];
void build(int node, int left, int right) {
  segtree[node].left = left;
  segtree[node].right = right;
  if (left == right) {
    segtree[node].val = 0;
    return;
  }
  int mid = (left + right) >> 1;
  build(node << 1, left, mid);
  build(node << 1 | 1, mid + 1, right);
  segtree[node].val =
      (segtree[node << 1].val + segtree[node << 1 | 1].val) % 1000000007;
}
void update(int node, int left, int right, int x, int d) {
  if (left == right) {
    segtree[node].val = d;
    return;
  }
  int mid = (left + right) / 2;
  if (mid >= x)
    update(node << 1, left, mid, x, d);
  else
    update(node << 1 | 1, mid + 1, right, x, d);
  segtree[node].val =
      (segtree[node << 1].val + segtree[node << 1 | 1].val) % 1000000007;
}
long long query(int node, int left, int right, int l, int r) {
  if (left > r || right < l) return 0;
  if (left >= l && right <= r) {
    return segtree[node].val;
  }
  int mid = (left + right) >> 1;
  return (query(node << 1, left, mid, l, r) +
          query(node << 1 | 1, mid + 1, right, l, r)) %
         1000000007;
}
bool cmp(P a, P b) { return a.e < b.e; }
long long dp[210000];
int b[210000];
int main() {
  int n, m, p, p1, i, cnt, num, s, t;
  while (~scanf("%d%d", &n, &m)) {
    cnt = 0;
    p = 0;
    p1 = 0;
    for (i = 1; i <= m; ++i) {
      scanf("%d%d", &bus[i].s, &bus[i].e);
      b[++cnt] = bus[i].s;
      b[++cnt] = bus[i].e;
      if (bus[i].e == n) p = 1;
      if (bus[i].s == 0) p1 = 1;
    }
    if (!p || !p1) {
      printf("0\n");
      continue;
    }
    sort(b + 1, b + 1 + cnt);
    num = unique(b + 1, b + 1 + cnt) - b - 1;
    for (i = 1; i <= m; ++i) {
      bus[i].s = lower_bound(b + 1, b + 1 + num, bus[i].s) - b;
      bus[i].e = lower_bound(b + 1, b + 1 + num, bus[i].e) - b;
    }
    sort(bus + 1, bus + 1 + m, cmp);
    memset(dp, 0, sizeof(dp));
    build(1, 1, num);
    dp[1] = 1;
    update(1, 1, num, 1, 1);
    for (i = 1; i <= m; ++i) {
      s = bus[i].s;
      t = bus[i].e;
      int q = query(1, 1, num, s, t - 1);
      dp[t] = (dp[t] + q) % 1000000007;
      update(1, 1, num, t, dp[t]);
    }
    printf("%lld\n", dp[num]);
  }
  return 0;
}
