#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
ll n, k;
bool check[200005];
ll dp[200005];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      check[j] = true;
    }
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n && i - j > 0; j++) {
      if (check[j]) {
        dp[i] = (dp[i] + dp[i - j]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}
