#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int MAX = 510000;
//const ll mod = 1000000007;
const ll mod = 998244353;
int main() {
  int n,k;
  cin >> n >> k;
  vector<pair<int,int>> q;
  
  int st,en;
  ll r[n+1] = {};
  ll imos[n+1] = {};
  imos[0] = 1;
  for(int i = 0;i<k;i++){
    cin >> st >> en;
    q.push_back(make_pair(st,en));
  }  
  for(int i = 1;i<n;i++){
    //cout << i << " " << imos[i] << " " << imos[i-1]<< endl;
    imos[i] = imos[i-1]+ imos[i];
    for(int j = 0;j<q.size();j++){
      st = q[j].first;
      en = q[j].second;
      //cout << i << " " << imos[i] << endl;
      if(i+st <= n){
        imos[i+st] += imos[i];
      }
      if(i+en+1<=n){
        imos[i+en+1] -= imos[i];
      }
    }
  }
 
  cout << imos[n];
}
