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

#define endl "\n"
#define int long long int
#define mod 1000000007
#define vi vector<int>
#define pint pair<int,int>
#define vint vector<vector<int>>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int N = 1e6+5;
int A[N], B[N], P[N];

int arr[15][2];
int modd = 998244353;

int mat[1005][1005];
pint edges[N];
unordered_map<int, set<int>> m;

bool compare(vi a, vi b)
{
    return a[0] < b[0];
}

int lcm(int a, int b)
{
    return (a*b)/(__gcd(a,b));
}

int mypow(int a, int x)
{
    if(a<=1 || x==1) return a;
    if(x==0) return 1;

    int temp = mypow(a,x/2);
    if(x%2==0) return ((temp%mod) * (temp%mod))%mod;
    else return (a%mod * ((temp%mod) * (temp%mod))%mod)%mod;
}

int count_bits(int n)
{
    int cnt = 0;
    while(n)
    {
        n = n & (n-1);
        cnt++;
    }return cnt;
}

void bfs(int src, int n)
{
    unordered_map<int, bool> visited;
    for(int i=0;i<n;i++) visited[i] = false;
    queue<int> q;
    q.push(src);
    visited[src] = true;

    while(!q.empty())
    {
        int curr = q.front();
        q.pop();
        B[curr] -= min(B[curr], A[src]);
        //cout<<curr<<" "<<endl;

        for(auto neigh: m[curr])
        {
            if(visited[neigh] == false)
            {
                //cout<<neigh<<endl;
                q.push(neigh);
                visited[neigh] = true;
                m[src].erase(neigh);
                m[neigh].erase(src);
            }
        }
    }
}

void void_solve(int n)
{

}

int int_solve(int n, int k)
{
    int i,j;
    vi v;
    for(i=0;i<k;i++)
    {
        for(j=arr[i][0];j<=arr[i][1];j++)
            v.push_back(j);
    }
    sort(v.begin(), v.end());

    int dp[n+1] = {0};
    dp[1] = 1;
    for(i=1;i<=n;i++)
    {
        for(int x:v)
        {
            if((x+i) <= n) dp[x+i] = (dp[x+i]%modd + dp[i]%modd)%modd;
        }
    }
    //for(i=1;i<=n;i++) cout<<dp[i]<<" ";
    //cout<<endl;
    return dp[n]%modd;
}

string string_solve(string s, int x)
{

}

bool bool_solve(int n)
{

}

int32_t main()
{
    //code
	IOS;

    int t,n,m,a,b,x,y,i,j,z;
    //cin>>t;
    t = 1;
    while(t--)
    {
        int k;
        cin>>n>>k;
        for(i=0;i<k;i++) cin>>arr[i][0]>>arr[i][1];
        cout<<int_solve(n,k)<<endl;

        //if(bool_solve(n)) cout<<"YES"<<endl;
        //else cout<<"NO"<<endl;
        //void_solve(n);


    }

	return 0;
}
