#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 2e5 + 3;
long long dp[N];
long long f(int n, vector<int> v) {
  if (n <= 0)
    return 0;
  else if (n == 1)
    return 1;
  else if (dp[n] != -1)
    return dp[n];
  else {
    long long total = 0;
    for (int i = 0; i < v.size(); i++) {
      total += f(n - v[i], v), total %= mod;
    }
    return dp[n] = total % mod;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  vector<int> v;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) v.push_back(j);
  }
  cout << f(n, v);
}
