#include <bits/stdc++.h>
using namespace std;
void data() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
}
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};
const int N = 1e6 + 100;
const long long mod = 1e6 + 3;
const long long big = 1e9;
const long long p = 27;
long long dp[N];
long long ok[N];
int main() {
  data();
  int n, k;
  cin >> n >> k;
  dp[1] = 1;
  int l[k + 1], r[k + 1];
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 1; i <= n; i++) {
    ok[i] += ok[i - 1];
    ok[i] %= 998244353LL;
    ;
    dp[i] += ok[i];
    dp[i] %= 998244353LL;
    if (dp[i] > 0) {
      for (int j = 1; j <= k; j++) {
        if (i + l[j] <= n) {
          ok[i + l[j]] += dp[i];
          ok[min(n + 1, i + r[j] + 1)] -= dp[i];
        }
      }
    }
  }
  cout << dp[n];
}
