#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void print1(T... t) {
  ((cout << t << " "), ...);
}
template <typename... T>
void print2(T... t) {
  vector<vector<long long>> ans = {t...};
  for (long long i = 0; i < (long long)ans.size(); i++) {
    if (i != 0)
      cout << "\t\t";
    else
      cout << "\t";
    for (long long j = 0; j < (long long)ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    if (i != (long long)ans.size() - 1) cout << endl;
  }
}
stringstream retvec;
template <typename... T>
void returnvector(T... t) {
  vector<vector<long long>> ans = {t...};
  for (long long i = 0; i < (long long)ans.size(); i++) {
    for (long long j = 0; j < (long long)ans[i].size(); j++) {
      retvec << ans[i][j];
      if (j != (long long)ans[i].size() - 1) retvec << " ";
    }
    if (i != (long long)ans.size() - 1) retvec << endl;
  }
}
template <typename T>
void printV(T vec) {
  for (int i = 0; i < (long long)vec.size(); i++)
    cout << vec[i] << " " << flush;
  cout << endl;
}
const long long INF = long long(1e9 + 5);
template <typename T>
void itR(T map) {
  for (auto itr = map.begin(); itr != map.end(); itr++) {
    {
      cout << " [ "
              "itr->first, itr->second"
           << " : ";
      print1(itr->first, itr->second);
      cout << "]" << endl;
    };
  }
  cout << endl;
}
string solve() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> vec(n);
  for (int i = 0; i < (long long)n; i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  vector<long long> dp(n);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - vec[j].first < 0 and i - vec[j].second - 1 < 0)
        continue;
      else if (i - vec[j].second - 1 < 0) {
        dp[i] = (dp[i] % long long(998244353) +
                 dp[i - vec[j].first] % long long(998244353)) %
                long long(998244353);
      } else {
        dp[i] = (dp[i] % long long(998244353) +
                 dp[i - vec[j].first] % long long(998244353) -
                 dp[i - vec[j].second - 1] % long long(998244353) +
                 long long(998244353)) %
                long long(998244353);
      }
    }
    dp[i] = (dp[i] % long long(998244353) + dp[i - 1] % long long(998244353)) %
            long long(998244353);
  }
  {
    stringstream returnn;
    returnn << dp[n - 1] - dp[n - 2];
    return returnn.str();
  };
}
int main() {
  cout << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  string ans1 = solve();
  if (ans1 != "") cout << ans1 << endl;
  return 0;
}
