#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k;
vector<pair<int, int>> s;
vector<long long> dp;
long long path(int x, vector<long long> &dp) {
  long long res = 0;
  for (int i = 0; i < k; i++) {
    for (int j = s[i].first; j <= s[i].second; j++) {
      if (x - j >= 0) {
        if (dp[x - j] != -1)
          res = (res + dp[x - j]) % mod;
        else
          res = (res + path(x - j, dp)) % mod;
      }
    }
  }
  dp[x] = res;
  return res;
}
int main() {
  cin >> n >> k;
  s.resize(k);
  for (int i = 0; i < k; i++) {
    cin >> s[i].first >> s[i].second;
  }
  dp.assign(n, -1);
  dp[0] = 1;
  cout << path(n - 1, dp) << endl;
}
