#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 10;
long long int dp[N];
vector<pair<int, int>> vec;
long long int solve(int curr, int tar) {
  if (curr > tar) {
    return 0;
  }
  if (curr == tar) {
    return 1;
  }
  if (dp[curr] != -1) {
    return dp[curr];
  }
  long long int res = 0;
  for (int i = 0; i < (int)vec.size(); i++) {
    for (int j = vec[i].first; j <= vec[i].second; j++) {
      res += solve(curr + j, tar);
      res %= 998244353;
    }
  }
  dp[curr] = (res + 998244353) % 998244353;
  return dp[curr];
}
int main() {
  int n, k;
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  unordered_set<int> st;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    vec.push_back({l, r});
  }
  long long int res = solve(1, n);
  res = (res + 998244353) % 998244353;
  cout << res << endl;
}
