#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <typename T>
T GCD(T a, T b) {
  long long t;
  while (a) {
    t = a;
    a = b % a;
    b = t;
  }
  return b;
}
template <typename T>
string toString(T a) {
  return to_string(a);
}
template <typename T>
void toInt(string s, T& x) {
  stringstream str(s);
  str >> x;
}
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline int mul(int x, int y) { return (x * 1ll * y) % mod; }
inline int powr(int a, long long b) {
  int x = 1 % mod;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return powr(a, mod - 2); }
vector<long long> dp(200005, -1);
long long rec(vector<pair<long long, long long> >& v, long long p,
              long long m) {
  if (dp[p] != -1) {
    return dp[p];
  }
  long long kk = 0;
  long long f = 0;
  for (auto x : v) {
    for (long long j = x.first; j <= x.second; j++) {
      if (p - j > 0) {
        long long h = rec(v, p - j, m);
        kk = add(kk, h);
      } else {
        f = 1;
        break;
      }
      if (f == 1) {
        break;
      }
    }
  }
  return dp[p] = kk;
}
void solve() {
  dp[1] = 1;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v(k);
  for (long long i = 0; i < k; i++) {
    cin >> v[i].first;
    cin >> v[i].second;
  }
  sort((v).begin(), (v).end());
  long long m = v.size();
  long long ans = rec(v, n, m);
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) solve();
}
