#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << fixed << setprecision(10);
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int>> lr;
  vector<long long int> v(n + 1);
  vector<long long int> sum(n + 1);
  v[1] = 1;
  sum[1] = 1;
  for (int i = 0, i_l = (k); i < i_l; i++) {
    long long int l, r;
    cin >> l >> r;
    lr.push_back(make_pair(l, r));
  }
  sort(lr.begin(), lr.end());
  for (int i = 2, i_l = (n + 1); i < i_l; i++) {
    for (int j = 0, j_l = (k); j < j_l; j++) {
      long long int l, r;
      l = ((0 < i - lr[j].second - 1) ? i - lr[j].second - 1 : 0);
      r = ((0 < i - lr[j].first) ? i - lr[j].first : 0);
      v[i] += (1000000007 + sum[r] - sum[l]) % 1000000007;
      v[i] %= 1000000007;
    }
    sum[i] = sum[i - 1] + v[i];
    sum[i] %= 1000000007;
  }
  cout << v[n] % 1000000007;
  return 0;
}
