/******

AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)

MOTTO : Use criticism as fuel and you will never run out of energy.
        AIM : TO BECOME A BETTER CODER
        INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
        Every moment is an opportunity to better yourself

*******/

#include<bits/stdc++.h>
using namespace std;
const int M = 998244353;
#define int unsigned long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define d(x) cout<<x<<"\n"
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

int ar[15];

int32_t main(void)
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		int n,z;
	cin>>n>>z;
	int k=z;
	set<int> s;
	while(k--)
    {
        int x,y;
        cin>>x>>y;
        s.insert(x);
        s.insert(y);
    }
    
    int ans = 0;
    for(auto i:s)
    {
        //cout<<i<<"\n";
        ar[ans] = i;
        ans++;
    }
    
    int N = n - 1;
    int m = ans;
    
    int count[N + 1] = {0}; 
    
    //memset(count, 0, sizeof(count)); 
    
    count[0] = 1; 
    
    for (int i = 1; i <= N; i++) 
    {
        for (int j = 0; j < m; j++) 
        {
            if (i >= ar[j]) 
            count[i] = (count[i]%M + count[i - ar[j]]%M)%M; 
        }
    }
                
    cout << (count[N])%M <<"\n"; 
	}
	//cerr << "\n" << "Time elapsed : " << time_passed << "\n";
	return 0;
}