#include <bits/stdc++.h>
using namespace std;
const int mx = 4e5 + 5;
long long mod = 998244353;
long long r[15];
long long l[15];
long long dp[mx], a[mx];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> l[i] >> r[i];
  }
  dp[1] = a[1] = 1;
  a[2] = -1;
  long long say = 0;
  for (int i = 1; i <= n; ++i) {
    say += a[i];
    say = say % mod;
    dp[i] = say;
    for (int j = 1; j <= k; ++j) {
      a[i + l[j]] += dp[i];
      a[i + r[j] + 1] -= dp[i];
    }
  }
  cout << dp[n] % mod << '\n';
}
