#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
void print() { cout << "\n"; }
template <typename T, typename... Types>
void print(T var1, Types... var2) {
  cout << var1 << " ";
  print(var2...);
}
template <typename T>
T fceil(T a, T b) {
  return (T)(a + b - 1) / b;
}
template <typename T>
void printvec(vector<T> v) {
  for (int i = 0; i < (int)v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}
template <typename T>
void printarr(T a[], int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
int main() {
  int n, q;
  cin >> n >> q;
  n--;
  vector<pair<int, int> > v;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp[0]) * (n + 1));
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto x : v) {
      for (int j = x.first; j <= x.second; j++) {
        if (i >= j) {
          dp[i] = (dp[i] + dp[i - j]) % MOD;
        }
      }
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
