#include <bits/stdc++.h>
using namespace std;
void __print(long long first) { cerr << first; }
void __print(long first) { cerr << first; }
void __print(unsigned first) { cerr << first; }
void __print(unsigned long first) { cerr << first; }
void __print(unsigned long long first) { cerr << first; }
void __print(float first) { cerr << first; }
void __print(double first) { cerr << first; }
void __print(long double first) { cerr << first; }
void __print(char first) { cerr << '\'' << first << '\''; }
void __print(const char *first) { cerr << '\"' << first << '\"'; }
void __print(const string &first) { cerr << '\"' << first << '\"'; }
void __print(bool first) { cerr << (first ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &first) {
  cerr << '{';
  __print(first.first);
  cerr << ',';
  __print(first.second);
  cerr << '}';
}
template <typename T>
void __print(const T &first) {
  long long f = 0;
  cerr << '{';
  for (auto &i : first) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long mod = 998244353;
vector<long long> fenwick;
long long n;
void update(long long i, long long val) {
  if (i > n) return;
  while (i <= n) {
    fenwick[i] = (fenwick[i] + val) % mod;
    i += i & (-i);
  }
}
long long query(long long val) {
  long long ans = 0;
  long long i = val;
  while (i > 0) {
    ans = (fenwick[i] + ans) % mod;
    i -= i & (-i);
  };
  return ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long k;
  cin >> n >> k;
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < k; i++) {
    long long t1, t2;
    cin >> t1 >> t2;
    v.push_back({t1, t2});
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 1; i < n; i++) {
    dp[i] = (dp[i] + mod) % mod;
    if (i != 2) {
      dp[i] = (dp[i - 1] + dp[i] + mod) % mod;
    }
    if (dp[i] <= 0 && i != 1) continue;
    for (long long j = 0; j < k; j++) {
      long long l = i + v[j].first;
      long long r = i + v[j].second;
      if (l <= n) {
        dp[l] = (dp[l] + dp[i] + mod) % mod;
      }
      if (r + 1 <= n) {
        dp[r + 1] = (dp[r + 1] - dp[i] + mod) % mod;
      }
    }
  }
  cout << (dp[n] + dp[n - 1] + mod) % mod;
  return 0;
}
