#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  pair<int, int> a[k];
  for (int i = 0; i < k; i++) {
    cin >> a[i].first >> a[i].second;
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  dp[2] = -1;
  long long suma = 0;
  for (int i = 1; i < n; i++) {
    suma += dp[i];
    suma = (suma + 998244353) % 998244353;
    for (int j = 0; j < k; j++) {
      if (a[j].first + i <= n) {
        dp[a[j].first + i] += suma;
        dp[a[j].first + i] %= 998244353;
      }
      if (a[j].second + i + 1 <= n) {
        dp[a[j].second + i + 1] -= suma;
        if (dp[a[j].second + i + 1] >= 0)
          dp[a[j].second + i + 1] %= 998244353;
        else
          dp[a[j].second + i + 1] =
              -((-1 * dp[a[j].second + i + 1]) % 998244353);
      }
    }
  }
  suma += dp[n];
  suma %= 998244353;
  cout << suma << "\n";
  return 0;
}
