#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 5;
const int MOD = 998244353;
vector<int> a;
vector<int> ans(mxn, -1);
int dp(int curr, int x, int n) {
  if (curr == n) {
    return 1;
  }
  int anss = 0;
  for (auto i : a) {
    if (curr + i <= n) {
      if (ans[curr + i] != -1) {
        anss += ans[curr + i];
      } else {
        anss += dp(curr + i, x, n);
      }
    }
    anss %= MOD;
  }
  return ans[curr] = anss;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, n, x, t1, t2;
  cin >> n >> x;
  for (i = 0; i < x; i++) {
    cin >> t1 >> t2;
    for (j = t1; j <= t2; j++) {
      a.push_back(j);
    }
  }
  dp(1, x, n);
  cout << ans[1];
  return 0;
}
