#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define endl "\n"

ll dp[200001];

ll recur(int n, vector<int> &v){

    if(n<1)
        return 0;

    if(n==1)
        return 1;
    
    if(dp[n]!=-1)
        return dp[n];

    ll ans=0;

    for(int i=0;i<v.size();i++){
        if(n-v[i]>0){
            ans+=recur(n-v[i], v);
        }
    }
    dp[n] = ans;
    return ans;
}

int main(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int t=1;
    // cin>>t;

    while(t--){
        ll n,k;
        cin>>n>>k;

        vector<int> v;
        bool b[n+1]={0};

        for(int i=0;i<k;i++){
            int x,y;
            cin>>x>>y;
            for(int j=x;j<=y;j++){
                v.push_back(j);
                b[j]=1;
            }
        }

        sort(v.begin(), v.end());

        dp[1] = 1;

        for(int j=2;j<=n;j++){
            ll ans=0;
            for(int i=0;i<v.size();i++){
                if(j-v[i]>=1){
                    ans+=dp[j-v[i]];
                }
                else
                    break;
            }
            dp[j]=ans;
        }

        cout<<dp[n]<<endl;
    }


    return 0;
}