#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long path(int t, int i, vector<long long>& v, vector<long long>& dp) {
  if (i == t) {
    return 1;
  }
  if (i > t) {
    return 0;
  }
  if (dp[i] != -1) {
    return dp[i];
  }
  long long a = 0;
  for (int k = 0; k < v.size(); k++) {
    a = (a + path(t, i + v[k], v, dp)) % mod;
  }
  return dp[i] = a % mod;
}
int main() {
  int t = 1;
  while (t--) {
    long long n, k, i, j;
    cin >> n >> k;
    set<long long> s;
    for (i = 0; i < k; i++) {
      long long a, b;
      cin >> a >> b;
      for (int l = a; l <= b; l++) {
        s.insert(l);
      }
    }
    vector<long long> v;
    for (auto it : s) {
      v.push_back(it);
    }
    vector<long long> dp(n + 1, -1);
    long long res = path(n - 1, 0, v, dp) % mod;
    cout << res % mod << endl;
  }
}
