#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> steps;
  vector<long long int> dp(n);
  dp[0] = 1;
  vector<long long int> pre(n);
  pre[0] = 1;
  for (int i = 0; i < k; ++i) {
    int start, end;
    cin >> start >> end;
    steps.push_back({start, end});
  }
  for (int i = 1; i < n; ++i) {
    for (pair<int, int> step : steps) {
      int left = i - step.second - 1;
      int right = i - step.first;
      if (left < i && right >= 0) {
        right = min(right, i - 1);
        left = max(left, -1);
        long long int leftval = (left == -1) ? 0 : pre[left];
        long long int rightval = pre[right];
        dp[i] = (dp[i] % 1000000009 +
                 (rightval - leftval + 1000000009) % 1000000009) %
                1000000009;
      }
    }
    pre[i] = (pre[i - 1] + dp[i]) % 1000000009;
  }
  cout << dp[n - 1] << '\n';
  return 0;
}
