#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
int n, k;
set <int> s;
int dp[MAXN];
int dfs(int v = 1) {
    if(~dp[v]) return dp[v];
    int res = (v == n);
    for(auto to : s)
        if(v + to <= n)
            res = (res + dfs(v + to) % MOD2;
    return dp[v] = res;
}

void solve() {
    memset(dp, -1, sizeof(dp));
    cin >> n >> k;
    for(int i = 1; i <= k; ++i) {
        int l, r;
        cin >> l >> r;
        while(l <= r) s.insert(l++);
    }
    cout << dfs();
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}
