#include <bits/stdc++.h>
using namespace std;
long long mod_v(long long num) {
  if (num >= 0)
    return (num % 1000000007);
  else
    return (num % 1000000007 + 1000000007) % 1000000007;
}
long long bigmod(long long b, long long p, long long m) {
  long long res = 1 % m, x = b % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
vector<int> v;
vector<pair<int, int> > bus;
map<int, int> mp;
long long bit[200005];
int n;
void update(int i, long long v) {
  while (i <= n) {
    bit[i] += v;
    i += (i & -i);
  }
}
long long query(int l) {
  long long sum = 0;
  while (l > 0) {
    sum += bit[l];
    l -= (l & -l);
  }
  return sum;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second < b.second)
    return true;
  else
    return false;
}
int main() {
  int m, l, r, len;
  long long q, ans;
  scanf("%d %d", &n, &m);
  v.push_back(0);
  v.push_back(n);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &l, &r);
    v.push_back(l);
    v.push_back(r);
    bus.push_back(make_pair(l, r));
  }
  sort(bus.begin(), bus.end(), cmp);
  sort(v.begin(), v.end());
  (v).erase(unique((v).begin(), (v).end()), (v).end());
  len = v.size();
  for (int i = 0; i < len; i++) {
    mp[v[i]] = i + 1;
  }
  n = mp[n];
  for (int i = 0; i < m; i++) {
    bus[i].first = mp[bus[i].first];
    bus[i].second = mp[bus[i].second];
  }
  update(1, 1);
  for (int i = 0; i < m; i++) {
    l = bus[i].first;
    r = bus[i].second;
    q = (query(r - 1) - query(l - 1)) % 1000000007;
    update(r, q);
  }
  ans = (query(n) - query(n - 1)) % 1000000007;
  printf("%I64d\n", ans);
}
