#include <bits/stdc++.h>
using namespace std;
void vout(vector<long long int> v) {
  for (long long int i = 0; i < v.size(); i++) cout << v.at(i) << endl;
}
long long int mod = 998244353;
struct modint {
  long long int x;
  modint(long long int x = 0) : x(x % mod) {}
  modint &operator+=(const modint a) {
    if ((x += a.x) >= mod) {
      x -= mod;
    }
    return *this;
  }
  modint &operator-=(const modint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  modint &operator*=(const modint a) {
    x *= a.x;
    x %= mod;
    return *this;
  }
  modint operator+(const modint a) const {
    modint copy(*this);
    return copy += a;
  }
  modint operator-(const modint a) const {
    modint copy(*this);
    return copy -= a;
  }
  modint operator*(const modint a) const {
    modint copy(*this);
    return copy *= a;
  }
  modint pow(long long int t) const {
    if (t == 0) return 1;
    modint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  modint inv() const { return pow(mod - 2); }
  modint operator/=(const modint a) { return (*this) *= a.inv(); }
  modint operator/(const modint a) {
    modint copy(*this);
    return copy /= a;
  }
};
int main() {
  cout << std::fixed << std::setprecision(10);
  long long int n;
  cin >> n;
  map<long long int, modint> dp;
  long long int k;
  cin >> k;
  set<pair<long long int, long long int> > s;
  for (int i = 0; i < (int)(k); i++) {
    long long int l, r;
    cin >> l >> r;
    s.insert(pair<long long int, long long int>(l, r));
  }
  modint a;
  a.x = 1;
  dp[0] = a;
  for (int i = 0; i < (int)(n); i++) {
    for (pair<long long int, long long int> v : s) {
      long long int l, r;
      if (i + v.first < n) {
        l = i + v.first;
        if (!dp.count(i + v.first)) {
          dp[i + v.first] = dp[i];
        } else {
          dp[i + v.first] += dp[i];
        }
        if (i + v.second < n && v.first != v.second) {
          r = i + v.second;
          if (!dp.count(i + v.second)) {
            dp[i + v.second] = dp[i];
          } else {
            dp[i + v.second] += dp[i];
          }
        } else if (i + v.first != n - 1 && v.first != v.second) {
          r = n - 1;
          if (!dp.count(n - 1)) {
            dp[n - 1] = dp[i];
          } else {
            dp[n - 1] += dp[i];
          }
        }
        for (auto v : dp) {
          modint an = dp[i];
          if (v.first > l && v.first < r) {
            dp[v.first] += dp[i];
          }
        }
      } else {
        break;
      }
    }
  }
  cout << dp[n - 1].x << endl;
  ;
}
