#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1000000007;
int n, m;
long long dp[N];
unordered_map<int, long long> cnt;
struct event {
  int L, R, id;
  bool operator<(const event &that) const { return R < that.R; }
} arr[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> arr[i].L >> arr[i].R;
    arr[i].id = i;
  }
  sort(arr, arr + m);
  set<pair<int, int> > st;
  long long sum = 0;
  for (int i = m - 1; i >= 0; i--) {
    while (!st.empty()) {
      auto it = *st.rbegin();
      if (it.first > arr[i].R) {
        sum = (sum - dp[it.second] + MOD) % MOD;
        st.erase(it);
      } else
        break;
    }
    dp[i] = (sum - cnt[arr[i].R] + (arr[i].R == n) + MOD) % MOD;
    sum = (sum + dp[i]) % MOD;
    cnt[arr[i].R] = (cnt[arr[i].R] + dp[i]) % MOD;
    st.insert(make_pair(arr[i].L, i));
  }
  long long ans = 0;
  for (int i = 0; i < m; i++)
    if (arr[i].L == 0) ans = (ans + dp[i]) % MOD;
  cout << ans << '\n';
}
