#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  int n, target;
  cin >> target >> n;
  target--;
  vector<pair<int, int>> c;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    c.push_back({a, b});
  }
  vector<int> dp(target + 1, 0);
  dp[0] = 1;
  for (int i = 1; i <= target; i++) {
    for (auto k : c) {
      for (int j = k.first; j <= k.second; j++) {
        if (i - j >= 0) {
          (dp[i] += dp[i - j]) %= mod;
        }
      }
    }
  }
  cout << dp[target] << endl;
}
