#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() {
  cout << endl;
  exit(0);
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
template <typename Head, typename... Tail>
void show(Head H, Tail... T) {
  cout << H << " ";
  show(T...);
}
template <typename Head, typename... Tail>
void pret(Head H, Tail... T) {
  cout << H << " ";
  pret(T...);
}
const long long MOD = 998244353;
const long long maxn = 3e5 + 10;
long long dp[maxn];
void add(long long l, long long r, long long x) {
  dp[l] += x;
  dp[l] %= MOD;
  if (r >= maxn) return;
  dp[r + 1] -= x;
  dp[r + 1] %= MOD;
}
int32_t main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < k; ++i) {
    long long l, r;
    cin >> l >> r;
    v.emplace_back(l, r);
  }
  add(1, 1, 1);
  for (long long i = 1; i <= (long long)n; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= MOD;
    for (const auto &it : v) {
      add(i + it.first, i + it.second, dp[i]);
    }
  }
  if (dp[n] < 0) dp[n] += MOD;
  show(dp[n]);
  return 0;
}
