#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define Mid ((L+R)/2)
#define pi pair<int,int>
#define pii pair<int,pi>
#define deb(x) cout<<#x<<"="<<x<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
set <int> s;
int n,mod=998244353,dp[200200];
int Solve(int i)
{
    if(i>n)
        return 0;
    if(i==n)
        return 1;
    int &ret=dp[i];
    if(ret+1)
        return ret;
    ret=0;
    for(int x : s)
    ret=(ret+Solve(i+x))%mod;
    return ret;
}
int main()
{
    go;
    cin>>n>>k;
    while(k--)
    {
        int x;
        cin>>x;
        s.insert(x);
        cin>>x;
        s.insert(x);
    }
    memset(dp,-1,sizeof dp);
    cout<<Solve(1);
    return 0;
}
