#include <bits/stdc++.h>
using namespace std;
long long tree[4 * 200005];
void build(vector<long long> &vec, int v, int tl, int tr) {
  if (tr == tl)
    tree[v] = vec[tr];
  else {
    int tm = (tl + tr) / 2;
    build(vec, 2 * v, tl, tm);
    build(vec, 2 * v + 1, tm + 1, tr);
    tree[v] = tree[2 * v] + tree[2 * v + 1];
    tree[v] %= 1000000007LL;
  }
}
long long query(int v, int tl, int tr, int l, int r) {
  if (l > tr or tl > r) return 0;
  if (l <= tl && tr <= r) return tree[v];
  int tm = (tl + tr) / 2;
  return (query(2 * v, tl, tm, l, r) + query(2 * v + 1, tm + 1, tr, l, r)) %
         1000000007LL;
}
void update(int v, int tl, int tr, int pos, long long val) {
  if (tl == tr) {
    tree[v] += val;
    tree[v] %= 1000000007LL;
    return;
  }
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    update(2 * v, tl, tm, pos, val);
  else
    update(2 * v + 1, tm + 1, tr, pos, val);
  tree[v] = tree[2 * v] + tree[2 * v + 1];
  tree[v] %= 1000000007LL;
}
int main() {
  int n, m, i, a, b;
  vector<pair<int, int>> v;
  map<int, int> mp;
  cin >> n >> m;
  set<int> st = {0, n};
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    v.push_back({b, a});
    st.insert(a);
    st.insert(b);
  }
  sort(v.begin(), v.end());
  i = 0;
  for (auto x : st) {
    mp[x] = i;
    i++;
  }
  for (i = 0; i < v.size(); i++) {
    v[i].first = mp[v[i].first];
    v[i].second = mp[v[i].second];
  }
  n = mp[n];
  long long sum = 0;
  vector<long long> ways(n + 1);
  ways[0] = 1;
  build(ways, 1, 0, n);
  for (auto x : v) {
    long long val = query(1, 0, n, x.second, x.first - 1);
    update(1, 0, n, x.first, val);
  }
  cout << query(1, 0, n, n, n) << '\n';
}
