#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1,
                            ans = 0;
  long long a, b;
  int fl, fl1, fl2, fl3;
  string s;
  long long f, size_f, size_s, weight1, weight2;
  long long sum, k_min, k_max, s1;
  long long da, db;
  cin >> n >> k;
  long long* l = new long long[k + 5];
  long long* r = new long long[k + 5];
  long long* dp = new long long[n + 5];
  for (i = 0; i < n + 2; i++) dp[i] = 0;
  dp[0] = 1;
  for (i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < k; j++)
      for (auto it = l[j]; it <= r[j]; it++)
        if (i + it < n) dp[i + it] = (dp[i + it] + dp[i]) % 998244353;
  }
  cout << dp[n - 1];
  return 0;
}
