#include <bits/stdc++.h>
using namespace std;
long long t[400010];
struct sg {
  long long b, e;
};
sg buses[100010];
long long N, M;
long long dp[100010];
long long last[100010];
bool cmp(sg a, sg b) { return a.e < b.e; }
long long sum(long long v, long long tl, long long tr, long long l,
              long long r) {
  if (l > r) return 0;
  if (l == tl && r == tr) {
    return t[v];
  }
  long long tm = (tl + tr) / 2;
  return (sum(v * 2, tl, tm, l, min(r, tm)) +
          sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)) %
         1000000007;
}
void updatesum(long long v, long long tl, long long tr, long long pos,
               long long new_val) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    long long tm = (tl + tr) / 2;
    if (pos <= tm)
      updatesum(v * 2, tl, tm, pos, new_val);
    else
      updatesum(v * 2 + 1, tm + 1, tr, pos, new_val);
    t[v] = (t[v * 2] + t[v * 2 + 1]) % 1000000007;
  }
}
long long bin(long long target) {
  long long l = 1, r = M + 1;
  while (l < r) {
    long long m = (l + r) / 2;
    if (buses[m].e < target) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  return l;
}
int main() {
  cin >> N >> M;
  for (long long i = 1; i <= M; i++) {
    cin >> buses[i].b >> buses[i].e;
  }
  sort(buses + 1, buses + M + 1, cmp);
  long long lastind = 0;
  buses[M + 1].e = numeric_limits<long long>::min();
  for (long long i = 1; i <= M; i++) {
    last[i] = lastind;
    if (buses[i].e != buses[i + 1].e) {
      lastind = i;
    }
  }
  for (long long i = 1; i <= M; i++) {
    long long l = bin(buses[i].b);
    if (buses[i].b == 0) {
      dp[i]++;
    }
    dp[i] += sum(1, 1, M + 1, l, last[i]) % 1000000007;
    updatesum(1, 1, M + 1, i, dp[i]);
  }
  long long ans = 0;
  for (long long i = 1; i <= M; i++) {
    if (buses[i].e == N) {
      ans = (ans + dp[i]) % 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
