#include <bits/stdc++.h>

using namespace std;

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define ll long long
const int MOD = 998244353;

class mint {
public:
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint &a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint &a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint &a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }

  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }
};

// 階乗を計算する
vector<mint> _factionals = {0, 1};
mint factional(long long n) {
  if (_factionals.size() <= n) {
    long long i = _factionals.size();
    _factionals.resize(n + 1);
    for (; i <= n; i++) {
      _factionals[i] = _factionals[i - 1] * i;
    }
  }
  return _factionals[n];
}

// 組み合わせ数を計算する。nCr
unordered_map<long long, vector<mint>> _combinations;
mint combination(long long n, long long r) {
  if (n < 1 || r < 1 || n < r)
    return mint(0);
  if (n == r)
    return mint(1);

  // nが小さい場合は公式を使う
  if (n < 51000)
    return factional(n) / (factional(r) * factional(n - r));

  // nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1) / r
  // nCr = nC(n - r)、計算量が少ない方を選ぶ
  if (r > n - r)
    r = n - r;
  // nC0 = 0, nC1 = nで初期化
  if (!_combinations.count(n))
    _combinations[n] = {0, n};
  auto &&vec = _combinations[n];
  if (vec.size() <= r) {
    long long i = vec.size();
    vec.resize(r + 1);
    for (; i <= r; i++) {
      vec[i] = (vec[i - 1] * (n - i + 1)) / i;
    }
  }

  return vec[r];
}

// 順序のパターン数を計算する。nPr
unordered_map<long long, vector<mint>> _permutations;
mint permutation(long long n, long long r) {
  if (n < 1 || r < 1 || n < r)
    return mint(0);

  // nが小さい場合は公式を使う
  if (n < 51000)
    return factional(n) / factional(n - r);

  // nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1)
  // nC0 = 0, nC1 = nで初期化
  if (!_permutations.count(n))
    _permutations[n] = {0, n};
  auto &&vec = _permutations[n];
  if (vec.size() <= r) {
    long long i = vec.size();
    vec.resize(r + 1);
    for (; i <= r; i++) {
      vec[i] = vec[i - 1] * (n - i + 1);
    }
  }

  return vec[r];
}

const int sqrtN = 2012;
struct SqrtDecomposition {
  int N, K;
  vector<mint> data;
  vector<mint> bucketAdd;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketAdd.assign(K, 0);
  }
  // [s, t)
  void add(int s, int t, mint x) {
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
      }
    }
  }
  mint get(int i) {
    int k = i / sqrtN;
    return data[i] + bucketAdd[k];
  }
};

int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << std::setprecision(20);

  cin >> n >> k;

  vector<int> l(k), r(k);
  SqrtDecomposition sd(n * 3 + 1);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }

  sd.add(0, 1, 1);
  for (int i = 0; i < n; i++) {
    for (int _k = 0; _k < k; _k++) {
      sd.add(i + l[_k], i + r[_k] + 1, sd.get(i));
    }
  }
  cout << sd.get(n - 1);
}

#include <bits/stdc++.h>

using namespace std;

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define ll long long
const int MOD = 998244353;

class mint {
public:
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint &a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint &a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint &a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }

  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }
};

// 階乗を計算する
vector<mint> _factionals = {0, 1};
mint factional(long long n) {
  if (_factionals.size() <= n) {
    long long i = _factionals.size();
    _factionals.resize(n + 1);
    for (; i <= n; i++) {
      _factionals[i] = _factionals[i - 1] * i;
    }
  }
  return _factionals[n];
}

// 組み合わせ数を計算する。nCr
unordered_map<long long, vector<mint>> _combinations;
mint combination(long long n, long long r) {
  if (n < 1 || r < 1 || n < r)
    return mint(0);
  if (n == r)
    return mint(1);

  // nが小さい場合は公式を使う
  if (n < 51000)
    return factional(n) / (factional(r) * factional(n - r));

  // nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1) / r
  // nCr = nC(n - r)、計算量が少ない方を選ぶ
  if (r > n - r)
    r = n - r;
  // nC0 = 0, nC1 = nで初期化
  if (!_combinations.count(n))
    _combinations[n] = {0, n};
  auto &&vec = _combinations[n];
  if (vec.size() <= r) {
    long long i = vec.size();
    vec.resize(r + 1);
    for (; i <= r; i++) {
      vec[i] = (vec[i - 1] * (n - i + 1)) / i;
    }
  }

  return vec[r];
}

// 順序のパターン数を計算する。nPr
unordered_map<long long, vector<mint>> _permutations;
mint permutation(long long n, long long r) {
  if (n < 1 || r < 1 || n < r)
    return mint(0);

  // nが小さい場合は公式を使う
  if (n < 51000)
    return factional(n) / factional(n - r);

  // nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1)
  // nC0 = 0, nC1 = nで初期化
  if (!_permutations.count(n))
    _permutations[n] = {0, n};
  auto &&vec = _permutations[n];
  if (vec.size() <= r) {
    long long i = vec.size();
    vec.resize(r + 1);
    for (; i <= r; i++) {
      vec[i] = vec[i - 1] * (n - i + 1);
    }
  }

  return vec[r];
}

const int sqrtN = 512;
struct SqrtDecomposition {
  int N, K;
  vector<mint> data;
  vector<mint> bucketAdd;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketAdd.assign(K, 0);
  }
  // [s, t)
  void add(int s, int t, mint x) {
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
      }
    }
  }
  mint get(int i) {
    int k = i / sqrtN;
    return data[i] + bucketAdd[k];
  }
};

int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << std::setprecision(20);

  cin >> n >> k;

  vector<int> l(k), r(k);
  SqrtDecomposition sd(n * 3 + 1);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }

  sd.add(0, 1, 1);
  for (int i = 0; i < n; i++) {
    for (int _k = 0; _k < k; _k++) {
      if (i + l[_k] < n) {

        sd.add(i + l[_k], min(i + r[_k] + 1, n), sd.get(i));
      }
    }
  }
  cout << sd.get(n - 1);
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 998244353;
const double EPS = 1e-10;

template <typename T> struct BIT {
  ll n = 0, msb = 0;
  vector<T> d;
  BIT(ll m) : d(m + 1) {
    n = d.size();
    for (ll i = 31; i >= 0; i--) {
      if (n >> i & 1) {
        msb = i;
        break;
      }
    }
  }
  void add(ll i, T x) {
    while (x < 0)
      x += MOD;
    x %= MOD;
    while (i < n) {
      d[i] += x;
      while (d[i] < 0)
        d[i] += MOD;
      d[i] %= MOD;
      i += i & -i;
    }
  }
  T sum(ll i) {
    T res = T();
    while (i > 0) {
      res += d[i];
      while (res < 0)
        res += MOD;
      res %= MOD;
      i -= i & -i;
    }
    return res;
  }
};

template <typename T> struct RangeAddBIT {
  BIT<ll> bit0, bit1;
  RangeAddBIT(ll n) : bit0(n + 1), bit1(n + 1) {}
  void add(ll l, ll r, T x) {
    bit0.add(l, -x * (l - 1));
    bit1.add(l, x);
    bit0.add(r + 1, x * r);
    bit1.add(r + 1, -x);
  }
  T sum(ll i) { return ((bit1.sum(i) * i) % MOD + bit0.sum(i)) % MOD; }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;
  ll l[k], r[k];
  int cnt[202020] = {};
  vector<pair<ll, ll>> lr;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    cnt[l[i]]++;
    cnt[r[i] + 1]--;
  }
  for (int i = 1; i < 202020; i++)
    cnt[i] += cnt[i - 1];
  int le = -1, ri = -1;
  for (int i = 0; i < 202020; i++) {
    if (cnt[i] == 0) {
      if (lr.empty()) {
        if (le == -1)
          continue;
        else {
          lr.emplace_back(pair<int, int>(le, ri));
          le = ri = -1;
        }
      } else if (le != -1) {
        lr.emplace_back(pair<int, int>(le, ri));
        le = ri = -1;
      }
    } else {
      if (le == -1) {
        le = ri = i;
      } else {
        ri++;
      }
    }
  }
  RangeAddBIT<ll> bit(202020);
  bit.add(1, 1, 1);
  for (int i = 1; i < n; i++) {
    ll t = bit.sum(i) - bit.sum(i - 1);
    while (t < 0)
      t += MOD;
    t %= MOD;
    for (int j = 0; j < lr.size(); j++) {
      ll x = i + lr[j].first, y = i + lr[j].second;
      if (x > n)
        continue;
      y = min(y, n);
      bit.add(x, y, t);
    }
  }
  ll ans = bit.sum(n) - bit.sum(n - 1);
  while (ans < 0)
    ans += MOD;
  ans %= MOD;
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 998244353;
const double EPS = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;
  ll l[k], r[k];
  for (ll i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  ll imos[202020] = {};
  imos[1] = 1;
  for (ll i = 1; i < n; i++) {
    imos[i] += imos[i - 1];
    imos[i] %= MOD;
    for (ll j = 0; j < k; j++) {
      ll x = i + l[j], y = i + r[j];
      if (x > n)
        continue;
      y = min(y, n);
      imos[x] += imos[i];
      imos[x] %= MOD;
      imos[y + 1] -= imos[i];
      while (imos[y + 1] < 0)
        imos[y + 1] += MOD;
    }
  }
  cout << (imos[n]) % MOD << endl;
}


#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;
// 繧ｨ繧､繝ｪ繧｢繧ｹ
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

// 螳壽焚
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 998244353;
const double pi = M_PI;

class BinaryIndexedTree {
public:
  BinaryIndexedTree(ll n);
  void add(ll i, ll x);
  ll sum(ll i);

private:
  vector<ll> nodes; // 1-indexed
  void init(ll n);
};

BinaryIndexedTree::BinaryIndexedTree(ll n) { init(n); }

void BinaryIndexedTree::init(ll n) {
  // 繝弱・繝峨・蛟､繧・縺ｫ蛻晄悄蛹・	for(ll i = 0; i < n + 1; i++)
  { nodes.push_back(0); }
}

void BinaryIndexedTree::add(ll i, ll x) {
  // i縺ｮ譛蠕後・1縺檎ｫ九▲縺ｦ縺・ｋ繝薙ャ繝医ｒ雜ｳ縺励※縺・￥
  while (i <= nodes.size()) {
    nodes[i] += x;
    i += i & -i;
  }
}

ll BinaryIndexedTree::sum(ll i) {
  ll result = 0;
  while (i > 0) {
    result = (result + nodes[i]) % mod;
    i -= i & -i;
  }
  return result;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> range(k);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    r++;
    range[i] = {l, r};
  }

  BinaryIndexedTree bit(n);
  // 蛻晄悄菴咲ｽｮ
  bit.add(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int lindex = i - range[j].second <= 0 ? 0 : i - range[j].second;
      int rindex = i - range[j].first <= 0 ? 0 : i - range[j].first;
      ll sum = (bit.sum(rindex) - bit.sum(lindex)) % mod;
      cout << lindex << " " << rindex << " " << sum << endl;
      bit.add(i, sum);
    }
  }
  cout << bit.sum(n) - bit.sum(n - 1) << endl;
}

#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;

using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 998244353;
const double pi = M_PI;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> range(k);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    r++;
    range[i] = {l, r};
  }

  vl dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (int j = 0; j < k; j++) {
      int lindex = i - range[j].second <= 0 ? 0 : i - range[j].second;
      int rindex = i - range[j].first <= 0 ? 0 : i - range[j].first;
      ll sum = (dp[rindex] - dp[lindex]) % mod;
      if (sum < 0)
        sum += mod;
      dp[i] += sum;
      dp[i] %= mod;
    }
  }
  ll result = dp[n] - dp[n - 1];
  if (result < 0) {
    result += mod;
  }
  cout << result << endl;
}


#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define __clock__
#else
#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

// tourist set
template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\\n'; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << '\\n'
#define p2(s, t) cout << (s) << " " << (t) << '\\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\\n'
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
#define p_yes() p("YES")
#define p_no() p("NO")
#define possible() p("Possible")
#define impossible() p("Impossible")

ll SUM(VI &V) { return accumulate(ALL(V), 0LL); }

ll MIN(VI &V) { return *min_element(ALL(V)); }
ll MAX(VI &V) { return *max_element(ALL(V)); }

void print_vector(VI &V) {
  ll n = V.size();
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << V[i];
  }
  cout << endl;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

// long double
using ld = long double;
#define EPS (1e-14)
#define equals(a, b) (fabs((a) - (b)) < EPS)

void no() {
  p_no();
  exit(0);
}
void yes() {
  p_yes();
  exit(0);
}

const ll mod = 998244353;
const ll inf = 1e18;
const double PI = acos(-1);

// snuke's mint
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
// const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// #include <atcoder/dsu>
// using namespace atcoder; // 忘れがち

// ei1333's BIT
// struct BIT {
//   vector<mint> data;
//   BIT(){}
//   BIT(ll sz) {
//     resize(sz);
//   }
//   void resize(ll sz){
//     data.assign(++sz, 0);
//   }
//   mint sum(ll k) {
//     mint ret = 0;
//     for(++k; k > 0; k -= k & -k) ret += data[k];
//     return (ret);
//   }
//   void add(ll k, ll x) {
//     for(++k; k < data.size(); k += k & -k) data[k] += x;
//   }
// };

// // 区間更新・区間和
// struct Range{
//   BIT P, Q;
//   Range(ll sz){
//     P.resize(sz+1);
//     Q.resize(sz+1);
//   }
//   // 範囲加算 [a, b) にwを加える
//   void update(ll a, ll b, ll w){
//     P.add(a, -w*a);
//     P.add(b,  w*b);
//     Q.add(a,  w);
//     Q.add(b, -w);
//   }
//   // [0, c)
//   mint simple_sum(ll c){
//     return P.sum(c) + Q.sum(c) * c;
//   }
//   // [a, b)
//   mint sum(ll a, ll b){
//     return simple_sum(b) - simple_sum(a);
//   }
// };

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  // input
  ll N, K;
  cin >> N >> K;

  VI L(K);
  VI R(K);
  rep(i, K) { cin >> L[i] >> R[i]; }

  vector<mint> dp(200200);
  vector<mint> Acc(200200);

  dp[0] = 1;
  rep(i, 200100) {
    // rep(i,10){
    if (i > 0)
      Acc[i] += Acc[i - 1];
    dp[i] += Acc[i];
    // debug(i, Acc)
    // debug(i, dp[i].x);
    // debug(i, Acc[i].x);

    // iから配る
    rep(j, K) {
      ll l = L[j];
      ll r = R[j];
      Acc[i + l] += dp[i];
      Acc[i + r + 1] -= dp[i];
    }
  }

  p(dp[N - 1].x);

  return 0;
}

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define __clock__
#else
#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

// tourist set
template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\\n'; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << '\\n'
#define p2(s, t) cout << (s) << " " << (t) << '\\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\\n'
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
#define p_yes() p("YES")
#define p_no() p("NO")
#define possible() p("Possible")
#define impossible() p("Impossible")

ll SUM(VI &V) { return accumulate(ALL(V), 0LL); }

ll MIN(VI &V) { return *min_element(ALL(V)); }
ll MAX(VI &V) { return *max_element(ALL(V)); }

void print_vector(VI &V) {
  ll n = V.size();
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << V[i];
  }
  cout << endl;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

// long double
using ld = long double;
#define EPS (1e-14)
#define equals(a, b) (fabs((a) - (b)) < EPS)

void no() {
  p_no();
  exit(0);
}
void yes() {
  p_yes();
  exit(0);
}

const ll mod = 998244353;
const ll inf = 1e18;
const double PI = acos(-1);

// snuke's mint
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
// const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// #include <atcoder/dsu>
// using namespace atcoder; // 忘れがち

// ei1333's BIT
// struct BIT {
//   vector<mint> data;
//   BIT(){}
//   BIT(ll sz) {
//     resize(sz);
//   }
//   void resize(ll sz){
//     data.assign(++sz, 0);
//   }
//   mint sum(ll k) {
//     mint ret = 0;
//     for(++k; k > 0; k -= k & -k) ret += data[k];
//     return (ret);
//   }
//   void add(ll k, ll x) {
//     for(++k; k < data.size(); k += k & -k) data[k] += x;
//   }
// };

// // 区間更新・区間和
// struct Range{
//   BIT P, Q;
//   Range(ll sz){
//     P.resize(sz+1);
//     Q.resize(sz+1);
//   }
//   // 範囲加算 [a, b) にwを加える
//   void update(ll a, ll b, ll w){
//     P.add(a, -w*a);
//     P.add(b,  w*b);
//     Q.add(a,  w);
//     Q.add(b, -w);
//   }
//   // [0, c)
//   mint simple_sum(ll c){
//     return P.sum(c) + Q.sum(c) * c;
//   }
//   // [a, b)
//   mint sum(ll a, ll b){
//     return simple_sum(b) - simple_sum(a);
//   }
// };

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  // input
  ll N, K;
  cin >> N >> K;

  VI L(K);
  VI R(K);
  rep(i, K) { cin >> L[i] >> R[i]; }

  vector<mint> dp(200200);
  vector<mint> Acc(200200);

  dp[0] = 1;
  rep(i, 200100) {
    // rep(i,10){
    if (i > 0)
      Acc[i] += Acc[i - 1];
    dp[i] += Acc[i];
    // debug(i, Acc)
    // debug(i, dp[i].x);
    // debug(i, Acc[i].x);

    // iから配る
    rep(j, K) {
      ll l = L[j];
      ll r = R[j];
      if (i + l < 200200) {
        Acc[i + l] += dp[i];
      }
      if (i + r + 1 < 200200) {
        Acc[i + r + 1] -= dp[i];
      }
    }
  }

  p(dp[N - 1].x);

  return 0;
}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>     //required

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef int ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(), a.end()
#define fr(i, x, y) for (int i = x; i < y; i++)
#define frr(i, x, y) for (int i = x - 1; i >= y; i--)
// #define inf 1e18+1
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll power(ll a, ll b) {
  ll ans = 1;
  while (b != 0) {
    if (b & 1) {
      ans *= a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
ll powerm(ll a, ll b) {
  ll ans = 1;
  while (b != 0) {
    if (b & 1) {
      ans *= a;
      ans %= mod;
    }
    a = a * a;
    a %= mod;
    b >>= 1;
  }
  return ans % mod;
}
VL dx = {1, 0, -1, 0};
VL dy = {0, 1, 0, -1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve() {
  ll n, k;
  cin >> n >> k;
  VL arr;
  fr(i, 0, k) {
    ll l, r;
    cin >> l >> r;
    fr(j, l, r + 1) { arr.pb(j); }
  }
  sort(ALL(arr));
  VL dp(n + 1, 0);
  dp[1] = 1;
  fr(i, 1, n + 1) {
    auto low = lower_bound(ALL(arr), i);
    if (low == arr.end()) {
      low--;
    }
    if (*low >= i) {
      if (low == arr.begin())
        continue;
      else {
        low--;
      }
    }
    ll x = low - arr.begin();
    fr(j, 0, x + 1) {
      if (i - arr[j] <= 0)
        break;
      dp[i] += dp[i - arr[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[n] % mod << endl;
  return;
}
int main() {
  IOS;
  ll t = 1, pp;
  // cin>>t;
  pp = t;
  while (t--) {
    // cout<<"Case #"<<pp-t<<": ";
    solve();
  }
  return 0;
}
/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 */
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>     //required

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(), a.end()
#define fr(i, x, y) for (int i = x; i < y; i++)
#define frr(i, x, y) for (int i = x - 1; i >= y; i--)
#define inf 1e18 + 1
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int mod = 998244353;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll power(ll a, ll b) {
  ll ans = 1;
  while (b != 0) {
    if (b & 1) {
      ans *= a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
ll powerm(ll a, ll b) {
  ll ans = 1;
  while (b != 0) {
    if (b & 1) {
      ans *= a;
      ans %= mod;
    }
    a = a * a;
    a %= mod;
    b >>= 1;
  }
  return ans % mod;
}
VL dx = {1, 0, -1, 0};
VL dy = {0, 1, 0, -1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<PLL> arr(k);
  fr(i, 0, k) cin >> arr[i].F >> arr[i].S;
  VL dp(n + 2, 0);
  dp[1] = 1;
  dp[2] = -1;
  fr(i, 1, n + 1) {
    dp[i] += dp[i - 1];
    fr(j, 0, k) {
      ll x = min(n + 1, i + arr[j].F);
      ll y = min(n + 1, i + arr[j].S + 1);
      dp[x] += dp[i];
      dp[x] %= mod;
      dp[y] -= dp[i];
      dp[y] += mod;
      dp[y] %= mod;
    }
    dp[i] %= mod;
  }
  cout << dp[n] << endl;
  return;
}
int main() {
  IOS;
  ll t = 1, pp;
  // cin>>t;
  pp = t;
  while (t--) {
    // cout<<"Case #"<<pp-t<<": ";
    solve();
  }
  return 0;
}
/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 */
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm


#include <algorithm>
#include <cstdio>
#include <vector>
typedef long long ll;

const ll mod = 998244353;
ll dp[202020];
std::vector<int> v;

ll dfs(int node) {
  ll res = 0;
  if (dp[node] >= 0)
    return dp[node];

  for (int i = 0; i < v.size(); i++) {
    if (node <= v[i])
      break;
    res = (res + dfs(node - v[i])) % mod;
  }

  return dp[node] = res % mod;
}

int main(void) {
  int N, K;
  scanf("%d%d", &N, &K);

  for (int i = 0; i < K; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) {
      v.push_back(j);
    }
  }
  std::sort(v.begin(), v.end());
  std::fill_n(dp, 202020, -1);
  dp[1] = 1;
  dfs(N);

  printf("%lld\\n", dp[N] % mod);

  return 0;
}

#include <algorithm>
#include <cstdio>
#include <vector>
typedef long long ll;

const ll mod = 998244353;
ll dp[202020];
std::vector<int> v[10];

struct Node {
  ll sum, lazy;
} tree[808080];

void lazy(int node, int l, int r) {
  tree[node].sum += tree[node].lazy * (r - l + 1);
  tree[node].sum %= mod;
  if (l != r) {
    tree[node * 2].lazy += tree[node].lazy;
    tree[node * 2 + 1].lazy += tree[node].lazy;
  }
  tree[node].lazy = 0;
}

Node merge(Node o1, Node o2) {
  Node me;
  me.sum = (o1.sum + o2.sum) % mod;
  me.lazy = 0;
  return me;
}

void updateRange(int node, int l, int r, int s, int e, ll x) {
  if (e < s)
    return;
  lazy(node, l, r);
  if (s > r || e < l) {
    return;
  }
  if (s <= l && e >= r) {
    tree[node].lazy += x;
    lazy(node, l, r);
    return;
  }
  int m = (l + r) >> 1;
  updateRange(node * 2, l, m, s, e, x);
  updateRange(node * 2 + 1, m + 1, r, s, e, x);
  tree[node] = merge(tree[node * 2], tree[node * 2 + 1]);
}

ll query(int node, int l, int r, int idx) {
  lazy(node, l, r);
  if (idx > r || idx < l) {
    return 0;
  }
  if (l == r) {
    return tree[node].sum % mod;
  }
  int m = (l + r) >> 1;
  return query(node * 2, l, m, idx) + query(node * 2 + 1, m + 1, r, idx);
}

void init(int node, int l, int r) {
  if (l == r) {
    tree[node] = {dp[l], 0};
    return;
  }
  int m = (l + r) >> 1;
  init(node * 2, l, m);
  init(node * 2 + 1, m + 1, r);
  tree[node] = merge(tree[node * 2], tree[node * 2 + 1]);
}

int main(void) {
  int N, K;
  scanf("%d%d", &N, &K);

  dp[0] = 1;
  for (int i = 0; i < K; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[i].push_back(x);
    v[i].push_back(y);
  }
  init(1, 0, N - 1);

  for (int j = 0; j < N; j++) {
    for (int i = 0; i < K; i++) {
      int st = j + v[i][0];
      int ed = std::min(j + v[i][1], N - 1);
      updateRange(1, 0, N - 1, st, ed, query(1, 0, N - 1, j));
    }
  }
  printf("%lld\\n", query(1, 0, N - 1, N - 1));

  return 0;
}


#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> vpii;
  REP(i, k) {
    ll a, b;
    cin >> a >> b;
    vpii.push_back({a, b});
  }
  vector<ll> memo(n + 1, 0);
  memo[1] = 1;
  vector<vector<int>> start(n + 1);
  vector<vector<int>> stop(n + 1);
  set<int> si;
  FOR(i, 1, n + 1) {
    if (!start[i].empty()) {
      REP(j, start[i].size()) { si.insert(start[i][j]); }
    }
    for (auto x : si) {
      memo[i] += memo[x];
      memo[i] %= MOD;
    }
    REP(j, k) {
      if (i + vpii[j].first <= n)
        start[i + vpii[j].first].push_back(i);
      if (i + vpii[j].second <= n)
        stop[i + vpii[j].second].push_back(i);
    }
    if (!stop[i].empty()) {
      REP(j, stop[i].size()) { si.erase(stop[i][j]); }
    }
  }
  cout << memo[n] << endl;
}

#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> vpii;
  REP(i, k) {
    ll a, b;
    cin >> a >> b;
    vpii.push_back({a, b});
  }
  vector<ll> memo(n + 1, 0);
  memo[1] = 1;
  vector<vector<int>> start(n + 1);
  vector<vector<int>> stop(n + 1);
  set<int> si;
  ll a = 0;
  FOR(i, 1, n + 1) {
    if (!start[i].empty()) {
      REP(j, start[i].size()) {
        a += memo[start[i][j]];
        a %= MOD;
      }
    }
    memo[i] += a;
    memo[i] %= MOD;
    REP(j, k) {
      if (i + vpii[j].first <= n)
        start[i + vpii[j].first].push_back(i);
      if (i + vpii[j].second <= n)
        stop[i + vpii[j].second].push_back(i);
    }
    if (!stop[i].empty()) {
      REP(j, stop[i].size()) {
        a = a - memo[stop[i][j]] + MOD;
        a %= MOD;
      }
    }
  }
  cout << memo[n] << endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int n, k;
  cin >> n >> k;

  int l[k], r[k];
  vector<mint> dp(n + 1);
  vector<mint> dp_sum(n + 1);

  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }

  dp[1] = 1;
  dp_sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int li = i - l[j];
      int ri = i - r[j] - 1;
      if (li <= 0)
        continue;
      li = max(li, 1);
      dp[i] += dp_sum[li] - dp_sum[ri];
    }
    dp_sum[i] = dp[i] + dp_sum[i - 1];
  }

  cout << dp[n] << endl;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; j++) {
      // [l[i], r[i]]
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1]; // dp[li]~dp[ri];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;

int main() {

  int n, k;
  cin >> n >> k;

  vector<int> range(n + 1, 0);
  vector<pair<int, int>> v;

  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
    range[x]++;
    range[y + 1]--;
  }

  for (int i = 1; i <= n; i++) {
    range[i] = range[i - 1] + range[i];
  }

  vector<int> poss;

  for (int i = 1; i <= n; i++) {
    if (range[i] >= 1) {
      poss.push_back(i);
    }
  }

  vector<int> dp(n + 1, 0);
  for (int i = 0; i < poss.size(); i++) {
    dp[poss[i]] = 1;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < poss.size(); j++) {
      if (poss[j] <= i) {
        dp[i] = (dp[i] % mod + dp[i - poss[j]] % mod) % mod;
      }
    }
  }

  cout << dp[n - 1] << endl;

  return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0, l, r;
  set<ll> st;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  ll dp[n + 1] = {};
  dp[0] = 1;
  dp[1] = -1;
  rep(i, k) {
    cin >> l >> r;
    r++;
    v[i].first = l, v[i].second = r;
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0)
      (dp[i] += dp[i - 1]) %= mod;
    for (int j = 0; j < k; ++j) {
      l = v[j].first, r = v[j].second;
      if (i + l < n)
        (dp[i + l] += dp[i]) %= mod;
      if (i + r < n)
        (dp[i + r] -= dp[i] - mod) %= mod;
      // if (i + r < n && dp[i + r] < 0) dp[i + r]+= mod;
    }
  }

  // rep(i, n - 1)(dp[i + 1] += dp[i]) %= mod;

  cout << dp[n - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX = 670;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int S;
  cin >> S;
  int L = S / 3, N = S % 3;
  ll ans = 0;
  while (L > 0) {
    ans = (ans + COM(L - 1 + N, N)) % MOD; // cout<< ans;
    L--;
    N += 3;
  }
  cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX = 2000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int S;
  cin >> S;
  int L = S / 3, N = S % 3;
  ll ans = 0;
  while (L > 0) {
    ans = (ans + COM(L - 1 + N, N)) % MOD; // cout<< ans;
    L--;
    N += 3;
  }
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

int64_t mod = 1000000007;

int64_t f(int n, vector<int64_t> &a) {
  if (a.at(n) != -1)
    return a.at(n);
  else {
    a.at(n) = (f(n - 1, a) + f(n - 3, a));
    a.at(n) %= mod;
    return a.at(n);
  }
}

int main() {
  int s;
  cin >> s;
  vector<int64_t> a(s + 1, -1);
  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }
  a.at(0) = 0, a.at(1) = 0, a.at(2) = 0;
  a.at(3) = 1, a.at(4) = 1, a.at(5) = 1;
  int64_t ans;
  ans = f(s, a);
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;

int64_t mod = 1000000007;

int64_t f(int n, vector<int64_t> &a) {
  if (a.at(n) != -1)
    return a.at(n);
  else {
    a.at(n) = (f(n - 1, a) + f(n - 3, a));
    a.at(n) %= mod;
    return a.at(n);
  }
}

int main() {
  int s;
  cin >> s;
  vector<int64_t> a(s + 1, -1);
  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }
  a.at(0) = 0, a.at(1) = 0, a.at(2) = 0;
  a.at(3) = 1;
  int64_t ans;
  ans = f(s, a);
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

vector<ll> dp;
ll ans = 0;
ll mod = 1e9 + 7;
int solve(int v) {
  // cout << v << endl;
  if (dp[v] > 1)
    return dp[v];

  for (int i = 3; v - i >= 0; i++)
    dp[v] = (dp[v] + solve(v - i)) % mod;

  return dp[v];
}

int main() {
  int n;
  cin >> n;

  dp.resize(n + 1, 1);
  dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1;

  cout << solve(n) % mod << endl;
  return 0;
}

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

vector<ll> dp;
ll ans = 0;
ll mod = 1e9 + 7;
int solve(int v) {
  // cout << v << endl;
  if (dp[v] > 1)
    return dp[v];

  for (int i = 3; v - i >= 0; i++)
    dp[v] = (dp[v] + solve(v - i)) % mod;

  return dp[v];
}

int main() {
  int n;
  cin >> n;
  if (n < 3)
    return cout << 0 << endl, 0;

  dp.resize(n + 1, 1);
  dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1;

  cout << solve(n) % mod << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\\n'

int dp[700][2001];

ll DFS(int i, int sum) {
  if (sum == 0)
    return 1;
  if (sum <= 2)
    return 0;
  if (dp[i][sum] != -1)
    return dp[i][sum];

  ll ans = 0;
  for (int x = 3; x <= sum; ++x) {
    ans += DFS(i + 1, sum - x);
    ans %= mod;
  }
  return dp[i][sum] = ans;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll S;
  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << DFS(0, S) << endl;
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\\n'

ll dp[2001];

ll DFS(int i, int sum) {
  if (sum == 0)
    return 1;
  if (sum <= 2)
    return 0;
  if (dp[sum] != -1)
    return dp[sum];

  ll ans = 0;
  for (int x = 3; x <= sum; ++x) {
    ans += DFS(i + 1, sum - x);
    ans %= mod;
  }
  return dp[sum] = ans;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll S;
  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << DFS(0, S) << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define orep(i, n) for (long long i = 1; i <= (n); ++i)     // one rep
#define drep(i, n) for (long long i = (n)-1; i >= 0; --i)   // down rep
#define srep(i, s, t) for (long long i = (s); i < (t); ++i) // set rep
#define rng(x) (x).begin(), (x).end()

// range
#define rrng(a) (a).rbegin(), (a).rend() // reverse range
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define ru(x, y) (((x) + (y)-1) / (y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vl = vector<ll>;

template <typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template <typename T> void pv(vector<T> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}

template <> void pv(vector<P> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << "<" << v.fi << "," << v.se << ">"
         << ",";
  }
  cout << "]" << endl;
}

template <typename T> void pv2(vector<vector<T>> vec) {
  for (auto &v : vec)
    pv(v);
}

// #include <bits/stdc++.h>
// using namespace std;

const int mod = 1000000007;
// const int mod = 998244353;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x -= a.x) < 0)
      x += mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint operator++() const { return mint(*this) += mint(1); }
  mint operator--() const { return mint(*this) -= mint(1); }
  mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

/*int main () {
  mint a= mod-1;
  cout << a.pow(2) << endl;
  cout << a.inv() << endl;
  mint b = 123;
  cout << b.inv() << endl;
  return 0;
}*/

mint dp[700][2005];
int main() {
  int n;
  cin >> n;

  rep(i, 2005) {
    if (i < 3)
      continue;
    dp[1][i] = mint(1);
  }

  orep(i, n / 3) orep(j, n) {
    rep(k, n) {
      if (k < 3)
        continue;
      if (j - k < 0)
        continue;
      dp[i + 1][j] += dp[i][j - k];
    }
  }

  mint ans = mint(0);
  orep(i, n / 3) ans += dp[i][n];
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define orep(i, n) for (long long i = 1; i <= (n); ++i)     // one rep
#define drep(i, n) for (long long i = (n)-1; i >= 0; --i)   // down rep
#define srep(i, s, t) for (long long i = (s); i < (t); ++i) // set rep
#define rng(x) (x).begin(), (x).end()

// range
#define rrng(a) (a).rbegin(), (a).rend() // reverse range
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define ru(x, y) (((x) + (y)-1) / (y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vl = vector<ll>;

template <typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template <typename T> void pv(vector<T> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}

template <> void pv(vector<P> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << "<" << v.fi << "," << v.se << ">"
         << ",";
  }
  cout << "]" << endl;
}

template <typename T> void pv2(vector<vector<T>> vec) {
  for (auto &v : vec)
    pv(v);
}

// #include <bits/stdc++.h>
// using namespace std;

const int mod = 1000000007;
// const int mod = 998244353;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x -= a.x) < 0)
      x += mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint operator++() const { return mint(*this) += mint(1); }
  mint operator--() const { return mint(*this) -= mint(1); }
  mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

/*int main () {
  mint a= mod-1;
  cout << a.pow(2) << endl;
  cout << a.inv() << endl;
  mint b = 123;
  cout << b.inv() << endl;
  return 0;
}*/

mint dp[700][2005];
int main() {
  int n;
  cin >> n;

  mint a = mint(1);
  rep(i, 2005) {
    if (i < 3)
      continue;
    dp[1][i] = a;
    a += 1;
  }

  orep(i, n / 3) orep(j, n) {
    if (j < 3 * (i + 1))
      continue;
    dp[i + 1][j] += dp[i + 1][j - 1] + dp[i][j - 3];
  }

  mint ans = mint(0);
  orep(i, n / 3) ans += dp[i][n] - dp[i][n - 1];
  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;

long long int mod(long long int x) {
  return (x % 1000000007 + 1000000007) % 1000000007;
}
int main() {
  long long int s;
  cin >> s;
  long long int dp[s + 2];
  for (int i = 0; i < s + 2; i++) {
    dp[i] = 0LL;
  }
  dp[0] = 1LL;
  dp[1] = 0LL, dp[2] = 0LL;
  dp[3] = 1LL;
  dp[4] = 1LL;
  dp[5] = 1LL;
  for (long long int i = 6; i <= s; i++) {
    for (long long int j = 3; j <= i; j++) {
      if (i - j >= 0 && i - j <= s && i >= 0 && i <= s)
        dp[i] = mod(mod(dp[i]) + mod(dp[i - j]));
    }
  }
  cout << mod(dp[s]) << endl;

  return 0;
}

#include <iostream>
using namespace std;
long long int dp[2005];
long long int mod(long long int x) {
  return (x % 1000000007 + 1000000007) % 1000000007;
}
int main() {
  long long int s;
  cin >> s;

  for (int i = 0; i < s + 2; i++) {
    dp[i] = 0LL;
  }
  dp[0] = 1LL;
  dp[1] = 0LL, dp[2] = 0LL;
  dp[3] = 1LL;
  dp[4] = 1LL;
  dp[5] = 1LL;
  for (long long int i = 6; i <= s; i++) {
    for (long long int j = 3; j <= i; j++) {
      if (i - j >= 0 && i - j <= s && i >= 0 && i <= s)
        dp[i] = mod(mod(dp[i]) + mod(dp[i - j]));
    }
  }
  cout << mod(dp[s]) << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll)1e20;
int iINF = (int)1e20;
ll mod = (ll)1e9 + 7;

signed main() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  fill(&dp[0], &dp[0] + n + 1, 0);
  dp[3] = 1;
  for (int i = 4; i <= n; ++i) {
    dp[i] = 1;
    for (int j = 3; j < i; ++j) {
      if (i - j >= 3) {
        dp[i] += dp[j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll)1e20;
int iINF = (int)1e20;
ll mod = (ll)1e9 + 7;

signed main() {
  ll n;
  cin >> n;
  vector<ll> dp(n + 100, 0);
  if (n < 3) {
    cout << 0;
    return 0;
  }
  dp[3] = 1;
  for (int i = 4; i <= n; ++i) {
    dp[i] = 1;
    for (int j = 3; j < i; ++j) {
      if (i - j >= 3) {
        dp[i] += dp[j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  vector<ll> A(s + 1);
  A[0] = 0;
  A[1] = 0;
  A[2] = 0;
  A[3] = 1;
  if (s < 4) {
    cout << A[s] << endl;
  } else {
    FOR(i, 4, s + 1) { A[i] = (A[i - 3] + A[i - 1]) % MOD; }
    cout << A[s] << endl;
  }
  return 0;
}

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  vector<ll> A;
  A.push_back(0);
  A.push_back(0);
  A.push_back(0);
  A.push_back(1);
  if (s < 4) {
    cout << A[s] << endl;
  } else {
    FOR(i, 4, s + 1) { A.push_back((A[i - 3] + A[i - 1]) % MOD); }
    cout << A[s] << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

void solve() {
  int s;
  cin >> s;

  ll dp[s + 1];

  dp[0] = dp[1] = dp[2] = 0;

  dp[3] = 1;

  for (int i = 4; i <= s; i++) {
    dp[i] = 0;
    for (int j = i - 3; j >= 3; j--) {
      dp[i] += (dp[j]) % mod;
      dp[i] %= mod;
    }
    dp[i] = (dp[i] + 1) % mod;
  }
  cout << dp[s];
}

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

void solve() {
  int s;
  cin >> s;

  ll dp[s + 1];

  if (s == 1 or s == 2) {
    cout << 0;
    return;
  }

  else if (s == 3) {
    cout << 1;
    return;
  }

  dp[0] = dp[1] = dp[2] = 0;

  dp[3] = 1;

  for (int i = 4; i <= s; i++) {
    dp[i] = 0;
    for (int j = i - 3; j >= 3; j--) {
      dp[i] += (dp[j]) % mod;
      dp[i] %= mod;
    }
    dp[i] = (dp[i] + 1) % mod;
  }
  cout << dp[s];
}

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}


#include <bits/stdc++.h>
#include <climits>

using namespace std;

#define debug(x, y)                                                            \\
  cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i, a, b) for (i = a; i < b; i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(), (x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
  if (n < 0 || n == 1 || n == 2 || l < 0)
    return 0;
  if ((l == 0 && n != 0) || (n == 0 && l != 0))
    return dp[n][l] = 0;
  if (n == 0 && l == 0) {
    return dp[n][l] = 1;
  }
  lld c = 0;
  if (dp[n][l] != -1)
    return dp[n][l];
  for (lld i = 3; i <= n; i++) {
    c += solve(n - i, l - 1);
    c %= MOD;
  }
  return dp[n][l] = c;
}

int main() {
  fast;
  cin.tie(0);
  lld n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    memset(dp, -1, sizeof(dp));
    lld cnt = 0;
    for (lld i = 1; i <= (n / 3) + 1; i++) {
      cnt += solve(n, i);
      cnt %= MOD;
    }
    cout << cnt << endl;
  }
}

#include <bits/stdc++.h>
#include <climits>

using namespace std;

#define debug(x, y)                                                            \\
  cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i, a, b) for (i = a; i < b; i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(), (x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
  if (n < 0 || n == 1 || n == 2 || l < 0)
    return 0;
  if ((l == 0 && n != 0) || (n == 0 && l != 0))
    return dp[n][l] = 0;
  if (n == 0 && l == 0) {
    return dp[n][l] = 1;
  }
  lld c = 0;
  if (dp[n][l] != -1)
    return dp[n][l];
  c += solve(n - 1, l);
  c %= MOD;
  c += solve(n - 3, l - 1);
  c %= MOD;
  return dp[n][l] = c;
}

int main() {
  fast;
  cin.tie(0);
  lld n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    memset(dp, -1, sizeof(dp));
    lld cnt = 0;
    for (lld i = 1; i <= (n / 3) + 1; i++) {
      cnt += solve(n, i);
      cnt %= MOD;
    }
    cout << cnt << endl;
  }
}


#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 20 + 5;
vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0));

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int k = 1; k < MAXN; k++) {
    dp[1][k] = k;
  }
  for (int s = 1; s < MAXN; s++) {
    dp[s][1] = 1;
  }
  for (int s = 2; s < MAXN; s++) {
    for (int k = 2; k < MAXN; k++) {
      dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD;
    }
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (int i = 1; i < S; i++) {
    ans += dp[max(S - 3 * i, 0)][i];
    if (S - 3 * i == 0)
      ans += 1;
    // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 2000 + 5;
vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0));

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int k = 1; k < MAXN; k++) {
    dp[1][k] = k;
  }
  for (int s = 1; s < MAXN; s++) {
    dp[s][1] = 1;
  }
  for (int s = 2; s < MAXN; s++) {
    for (int k = 2; k < MAXN; k++) {
      dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD;
    }
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (int i = 1; i < S; i++) {
    ans += dp[max(S - 3 * i, 0)][i];
    if (S - 3 * i == 0)
      ans += 1;
    // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}


#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll MOD = 1e9 + 7;
  int S;
  cin >> S;
  vector<ll> ans(S + 1, 0);
  ans[3] = 1;
  for (int i = 4; i <= S; i++) {
    ans[i] = (ans[i - 1] + ans[i - 3]) % MOD;
  }
  cout << ans[S] << endl;
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll MOD = 1e9 + 7;
  int S;
  cin >> S;
  vector<ll> ans(S + 1, 0);
  ans[0] = 1;
  for (int i = 3; i <= S; i++) {
    ans[i] = (ans[i - 1] + ans[i - 3]) % MOD;
  }
  cout << ans[S] << endl;
  return 0;
}


// 177

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main() {
  int s;
  ll ans = 0;
  cin >> s;
  vector<vector<ll>> v(s - 2, vector<ll>(s - 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v.at(i).at(0) = 1;
  }
  for (int i = 1; i < v.size(); i++) {
    for (int j = 1; j < i + 1; j++) {
      v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM;
    }
  }
  for (int i = 1; s >= 3 * i; i++) {
    ans += v.at(s - i * 2 - 1).at(i - 1);
    ans %= NUM;
  }
  cout << ans << endl;
  return 0;
}

// 177

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main() {
  int s;
  ll ans = 0;
  cin >> s;
  vector<vector<ll>> v(s, vector<ll>(s + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v.at(i).at(0) = 1;
  }
  for (int i = 1; i < v.size(); i++) {
    for (int j = 1; j < i + 1; j++) {
      v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM;
    }
  }
  for (int i = 1; s >= 3 * i; i++) {
    ans += v.at(s - i * 2 - 1).at(i - 1);
    ans %= NUM;
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\\n"
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

ll fa[1000001];
ll inv[1000001];

ll modex(ll a, ll b) {
  if (b <= 0) {
    return 1;
  }
  if (b % 2 == 0) {
    ll x = modex(a, b / 2);
    return ((x * x) % mod);
  } else
    return ((a % mod * modex(a, b - 1)) % mod);
}
ll fact() {
  fa[0] = 1;
  for (int i = 1; i <= 3000; i++) {
    fa[i] = (fa[i - 1] * i) % mod;
  }
}

ll invfact() {
  inv[0] = 1;
  for (int i = 1; i <= 3000; i++)
    inv[i] = (inv[i - 1] * modex(i, mod - 2)) % mod;
}

ll ncr(ll n, ll r) {
  ll ans = (fa[n] * inv[n - r]) % mod;
  ans = (ans * inv[r]) % mod;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(12);
  ll n;
  cin >> n;
  fact();
  invfact();
  // for(ll i=1;i<=2000;i++){
  // cout<<ncr(0, 0)<<endl;
  ll r = 1, x = (n - 2 * r - 1), an = 0;
  while (x >= (r - 1) && x >= 0 && (r - 1) >= 0) {
    an = (an + ncr(x, r - 1)) % mod;
    r++;
    x = (n - 2 * r - 1);
  }
  cout << an << endl;
  //}
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\\n"
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

ll c[2001][2001];

void combina() {
  for (int i = 0; i <= 2000; i++)
    for (int j = 0; j <= i; j++) {
      if (j == i || j == 0)
        c[i][j] = 1;
      else
        c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      c[i][j] %= mod;
    }
  // return c[i][j];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(12);
  ll n;
  cin >> n;
  combina();
  ll r = 1, an = 0;
  while ((n - 2 * r - 1) >= 0) {
    ll x = n - 2 * r - 1;
    an = (an + c[x][r - 1]) % mod;
    r++;
  }
  cout << an << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long _ulong;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end)                                                     \\
  for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define endk '\\n'
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = {0, -1, 1, 0, 1, -1, 1, -1}, dy[8] = {1, 0, 0, -1, -1, -1, 1, 1};
typedef pair<lint, char> pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;

public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, lint n) {
  ModInt ret = 1;
  while (n > 0) {
    if (n & 1)
      (ret *= x);
    (x *= x);
    n >>= 1;
  }
  return ret;
}

ModInt func[200000];
void funcinit(int N) {
  func[0] = 1;
  for (int i = 1; i <= N; i++) {
    func[i] = func[i - 1] * i;
  }
}
ModInt comb(ModInt n, ModInt r) {
  if (n.a <= 0 || n.a < r.a) {
    return 1;
  }
  return func[n.a] / (func[r.a] * func[(n - r).a]);
}

lint S;
ModInt dp[2001][2001];
int main() {
  cin >> S;
  FOR(i, 3, S + 1) dp[1][i] = 1;
  FOR(i, 1, S + 1) {
    REP(j, S + 1) {
      FOR(k, 3, S + 1) {
        if (j - k >= 0)
          dp[i][j] += dp[i - 1][j - k];
      }
    }
  }
  ModInt ans = 0;
  REP(i, S + 1) { ans += dp[i][S]; }
  cout << ans.a << endk;
}

#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long _ulong;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end)                                                     \\
  for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define endk '\\n'
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = {0, -1, 1, 0, 1, -1, 1, -1}, dy[8] = {1, 0, 0, -1, -1, -1, 1, 1};
typedef pair<lint, char> pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;

public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, lint n) {
  ModInt ret = 1;
  while (n > 0) {
    if (n & 1)
      (ret *= x);
    (x *= x);
    n >>= 1;
  }
  return ret;
}

ModInt func[200000];
void funcinit(int N) {
  func[0] = 1;
  for (int i = 1; i <= N; i++) {
    func[i] = func[i - 1] * i;
  }
}
ModInt comb(ModInt n, ModInt r) {
  if (n.a <= 0 || n.a < r.a) {
    return 1;
  }
  return func[n.a] / (func[r.a] * func[(n - r).a]);
}

lint S;
ModInt dp[2001][2001];
int main() {
  cin >> S;
  FOR(i, 3, S + 1) dp[1][i] = 1;
  FOR(i, 1, S + 1) {
    REP(j, S) dp[i][j + 1] += dp[i][j];
    FOR(j, 6, S + 1) { dp[i + 1][j] += dp[i][j - 3] - dp[i][2]; }
  }
  ModInt ans = 0;
  REP(i, S) { ans += dp[i][S] - dp[i][S - 1]; }
  cout << ans.a << endk;
}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {
  long long s;
  cin >> s;

  vector<long long> dp(s + 1, 0LL);

  int i, j;

  long long hell = 1e9 + 7;

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  for (i = 6; i <= s; i++) {
    for (j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % hell;

    dp[i] = (dp[i] + 1LL) % hell;
  }
  cout << dp[s] << endl;
}

int main() {
  int t = 1;
  // cin>>t;

  while (t--) {
    solve();
  }
}

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {
  long long s;
  cin >> s;

  vector<long long> dp(s + 1, 0LL);

  int i, j;

  long long hell = 1e9 + 7;

  if (s <= 2) {
    cout << 0 << endl;
    return;
  }
  if (s <= 5) {
    cout << 1 << endl;
    return;
  }

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  for (i = 6; i <= s; i++) {
    for (j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % hell;

    dp[i] = (dp[i] + 1LL) % hell;
  }
  cout << dp[s] << endl;
}

int main() {
  int t = 1;
  // cin>>t;

  while (t--) {
    solve();
  }
}


#include <algorithm>
#include <cstdio>
#define ll long long
using namespace std;
int f[2005][2005];
const ll mod = 1e9 + 7;
#define R register
int main() {
  // long long n;
  R int i, j, k, n, ans = 0;
  scanf("%lld", &n);
  f[0][0] = 1;
  for (i = 0; i <= n / 3; ++i) { // 最多这么多轮
    for (j = i * 3; j <= n; ++j) {
      for (k = 3; k <= n - j; ++k)
        f[i + 1][j + k] += f[i][j], f[i + 1][j + k] > mod
                                        ? f[i + 1][j + k] -= mod
                                        : f[i + 1][j + k] ^= 0;
    }
  }
  for (i = 1; i <= n / 3; ++i)
    ans += f[i][n], ans %= mod;
  printf("%lld\\n", ans);
}

#include <algorithm>
#include <cstdio>
#define ll long long
using namespace std;
int f[2005][2005];
const ll mod = 1e9 + 7;
#define R register
int main() {
  // long long n;
  R int i, j, k, n, ans = 0;
  scanf("%d", &n);
  f[0][0] = 1;
  for (i = 0; i <= n / 3; ++i) { // 最多这么多轮
    for (j = i * 3; j <= n; ++j) {
      for (k = 3; k <= n - j; ++k)
        f[i + 1][j + k] += f[i][j], f[i + 1][j + k] > mod
                                        ? f[i + 1][j + k] -= mod
                                        : f[i + 1][j + k] ^= 0;
    }
  }
  for (i = 1; i <= n / 3; ++i)
    ans += f[i][n], ans %= mod;
  printf("%d\\n", ans);
}

*** stack smashing detected ***: terminated


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

// const long long mod = (long long)1e9 + 7;
int main() {
  long long s;
  cin >> s;

  long long dp[s + 1];

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= s; ++i) {
    dp[i] = 1;
    for (int j = 3; j <= i; j++) {
      if (i - j >= 3) {
        dp[i] = (dp[i] + dp[j]) % mod;
      }
    }
  }
  cout << dp[s] << endl;

  return 0;
}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

// const long long mod = (long long)1e9 + 7;
int main() {
  long long s;
  cin >> s;

  long long dp[2005];

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= s; ++i) {
    dp[i] = 1;
    for (int j = 3; j <= i; j++) {
      if (i - j >= 3) {
        dp[i] = (dp[i] + dp[j]) % mod;
      }
    }
  }
  cout << dp[s] << endl;

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;

const int maxn = 2010;
const int M = 1000000007;

int n;
ll ans;
ll dp[maxn][maxn]; // 分为 i 组 ， 和为 j 的方案数

ll read() {
  ll s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}

int main() {
  n = read();
  if (n < 3)
    printf("0\\n");
  else {
    dp[0][0] = 1ll;
    for (int i = 1; i <= n / 3; ++i) {
      for (int j = 3; j <= n; ++j) {
        for (int k = 3; k <= j; ++k) {
          dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % M;
        }
      }
    }
    for (int i = 1; i <= n / 3; ++i) {
      ans = (ans + dp[i][n]) % M;
    }
    printf("%lld\\n", ans);
  }

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 2010;
const int M = 1000000007;

int n, m, gr;
ll ans, s;
ll dp[maxn][maxn]; // 分为 i 组 ， 和为 j 的方案数
ll fac[maxn];

ll ksm(ll i, ll po) {
  i %= M;
  ll res = 1;
  while (po) {
    if (po & 1)
      res = res * i % M;
    po >>= 1;
    i = i * i % M;
  }
  return res;
}

ll inv(ll a) { return ksm(a, M - 2); }

ll c(ll N, ll K) {
  if (N < K)
    return 0;
  if (N < 0 || K < 0)
    return 0;
  return 1ll * fac[N] * inv(fac[K]) % M * inv(fac[N - K]) % M;
}

ll read() {
  ll s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}

int main() {
  fac[0] = 1ll;
  for (int i = 1; i <= 2001; i++)
    fac[i] = 1LL * fac[i - 1] * i % M;

  ans = 0;
  // printf("%lld\\n",c(3,1));
  s = read();
  if (s < 3)
    printf("0\\n");
  else {
    gr = s / 3LL;

    for (int i = 1; i <= gr; i++) {
      m = s - 3ll * i;
      //			printf("%lld\\n",c(m+i-1ll,i-1ll));
      ans = (ans + c(m + i - 1ll, i - 1ll)) % M;
    }
    printf("%d\\n", (ans + M) % M);
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define COUT(x) cout << (x) << "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define REP(i, n) for (int i = 0; i < n; i++)
#define YES(x) cout << (x ? "YES" : "NO") << "\\n"
#define Yes(x) cout << (x ? "Yes" : "No") << "\\n"
#define dump(x) cout << #x << " = " << (x) << "\\n"
#define endl "\\n"
using G = vector<vector<int>>;
using M = map<int, int>;
using P = pair<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct {
  int to;
  int cost;
};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
  IOS;
  int s;
  cin >> s;
  vector<int> dp(s);

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= s; j++) {
      if (i < j)
        break;

      dp[i] += dp[i - j];
      dp[i] %= mod;
    }
  }

  COUT(dp[s]);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define COUT(x) cout << (x) << "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define REP(i, n) for (int i = 0; i < n; i++)
#define YES(x) cout << (x ? "YES" : "NO") << "\\n"
#define Yes(x) cout << (x ? "Yes" : "No") << "\\n"
#define dump(x) cout << #x << " = " << (x) << "\\n"
#define endl "\\n"
using G = vector<vector<int>>;
using M = map<int, int>;
using P = pair<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct {
  int to;
  int cost;
};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

vector<int> dp(2000);

int main() {
  IOS;
  int s;
  cin >> s;

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= s; j++) {
      if (i < j)
        break;

      dp[i] += dp[i - j];
      dp[i] %= mod;
    }
  }

  COUT(dp[s]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int dp[2010];
int solve(int n) {
  if (n == 0)
    return 1;
  if (n == 1 and n == 2)
    return 0;
  if (n >= 3 and n <= 5)
    return 1;
  if (dp[n] != -1)
    return dp[n];
  int ans = 0;
  for (int i = 3; i <= n; i++) {
    if (n - i >= 0) {
      int temp = (solve(n - i)) % mod;
      ans = (ans + temp) % mod;
    }
  }
  return ans;
}
int32_t main() {
  IOS;
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n) << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int dp[2010];
int solve(int n) {
  if (n == 0)
    return 1;
  if (n == 1 and n == 2)
    return 0;
  if (n >= 3 and n <= 5)
    return 1;
  if (dp[n] != -1)
    return dp[n];
  int ans = 0;
  for (int i = 3; i <= n; i++) {
    if (n - i >= 0) {
      int temp = (solve(n - i)) % mod;
      ans = (ans + temp) % mod;
    }
  }
  return dp[n] = ans;
}
int32_t main() {
  IOS;
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n) << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;
const int N = 700;

long long dp[N][2001];

void solve() {
  int s;
  cin >> s;

  memset(dp, -1, sizeof(dp));

  function<long long(int, int)> f = [&](int i, int sum) -> long long {
    if (sum > s)
      return 0;
    if (dp[i][sum] != -1)
      return dp[i][sum];
    if (sum == s)
      return 1;
    long long ret = 0;
    for (int k = 3; k <= s - sum; ++k) {
      ret += f(i + 1, sum + k);
      ret %= MOD;
    }
    return dp[i][sum] = ret;
  };

  cout << f(0, 0) << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;
const int N = 700;

long long dp[2001];

void solve() {
  int s;
  cin >> s;

  memset(dp, -1, sizeof(dp));

  function<long long(int)> f = [&](int sum) -> long long {
    if (sum < 0)
      return 0;
    if (dp[sum] != -1)
      return dp[sum];
    if (sum == 0)
      return 1;
    long long ans = 0;
    for (int i = 3; i <= sum; ++i) {
      ans += f(sum - i);
      ans %= MOD;
    }
    return dp[sum] = ans;
  };

  cout << f(s) << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <assert.h>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
#define lld long long int
#define newline cout << endl
#define pb push_back
#define mp make_pair
lld shouldendl = 1;
#define se second
#define fi first
#define sfind(s, ele) (s).find((ele));
#define SPEED                                                                  \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define starttime                                                              \\
  chrono::time_point<chrono::system_clock> start, end;                         \\
  start = chrono::system_clock::now()
#define showtime                                                               \\
  end = chrono::system_clock::now();                                           \\
  chrono::duration<double> elapsed_seconds = end - start;                      \\
  time_t end_time = chrono::system_clock::to_time_t(end);                      \\
  cout << "elapsed time: " << elapsed_seconds.count() << "s\\n"
lld INF = (lld)(1e9 + 7);
lld MOD = (lld)(1e9 + 7);
#define fileopen                                                               \\
  freopen("input.txt", "rt", stdin);                                           \\
  freopen("output.txt", "wt", stdout);
using namespace std;
lld modInverse(lld a) {
  lld m = MOD, m0 = m, y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    lld q = a / m, t = m;
    m = a % m, a = t, t = y;
    y = x - q * y, x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}
lld add(long long a, long long b) { return ((a % MOD) + (b % MOD)) % MOD; }
lld mul(long long a, long long b) { return ((a % MOD) * (b % MOD)) % MOD; }
lld sub(long long a, long long b) {
  lld ans = ((a % MOD - b % MOD)) % MOD;
  if (ans < 0)
    ans += MOD;
  return ans;
}
lld gcd(lld a, lld b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
void MAIN(lld i, lld t);
int get() {
  lld t;
  cin >> t;
  ;
  return t;
}
template <class T> int logd(T name) {
  cout << name << endl;
  return 0;
}
void test(int t) {
  for (lld i = 1; i <= t; i++) {
    MAIN(i, t);
    if (shouldendl)
      cout << endl;
  }
}
lld power(lld x, lld y) {
  lld res = 1;
  x = x % MOD;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    y = y >> 1;
    x = (x * x) % MOD;
  }
  return res;
}
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {
  return {l.first + r.first, l.second + r.second};
}
#define all(v) (v).begin(), (v).end()
lld popcount(lld x) { return __builtin_popcountll(x); }
lld lcm(lld a, lld b) { return (a * b) / gcd(a, b); }
template <class T> bool input(vector<T> &v, lld n = -1) {
  assert(v.size() != 0);
  if (n == -1)
    n = v.size();
  for (auto &i : v)
    cin >> i;
  return 0;
}
template <class T> bool print(vector<T> v, lld l = 0, lld r = -1) {
  if (r == -1)
    r = v.size();
  for (int i = l; i < r; i++)
    cout << v[i] << " ";
  return 0;
}
// Observation, binary_search, dfs on strings, simplify the problem
// Observe and ELIMINATE
lld sum;
lld n;
lld dp[2001][2001];
lld solve(lld j, lld temp) {
  if (temp > sum)
    return 0;
  if (j >= sum)
    return 0;
  if (temp == sum)
    return 1;

  if (dp[j][temp] != -1)
    return dp[j][temp];

  lld p = 0;
  for (lld i = 3; i <= sum; i++) {
    p = add(p, solve(j + 1, temp + i));
  }
  return dp[j][temp] = p;
}
void MAIN(lld current_test_case, lld total_test_cases) {

  cin >> sum;
  lld ans = 0;
  memset(dp, (lld)-1, sizeof(dp));
  ans += solve(0, 0);

  cout << ans;
}
int main() {

  SPEED;
#ifndef ONLINE_JUDGE
  fileopen
#endif
      test(1);
  return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <assert.h>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
#define lld long long int
#define newline cout << endl
#define pb push_back
#define mp make_pair
lld shouldendl = 1;
#define se second
#define fi first
#define sfind(s, ele) (s).find((ele));
#define SPEED                                                                  \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define starttime                                                              \\
  chrono::time_point<chrono::system_clock> start, end;                         \\
  start = chrono::system_clock::now()
#define showtime                                                               \\
  end = chrono::system_clock::now();                                           \\
  chrono::duration<double> elapsed_seconds = end - start;                      \\
  time_t end_time = chrono::system_clock::to_time_t(end);                      \\
  cout << "elapsed time: " << elapsed_seconds.count() << "s\\n"
lld INF = (lld)(1e9 + 7);
lld MOD = (lld)(1e9 + 7);
#define fileopen                                                               \\
  freopen("input.txt", "rt", stdin);                                           \\
  freopen("output.txt", "wt", stdout);
using namespace std;
lld modInverse(lld a) {
  lld m = MOD, m0 = m, y = 0, x = 1;
  if (m == 1)
    return 0;
  while (a > 1) {
    lld q = a / m, t = m;
    m = a % m, a = t, t = y;
    y = x - q * y, x = t;
  }
  if (x < 0)
    x += m0;
  return x;
}
lld add(long long a, long long b) { return ((a % MOD) + (b % MOD)) % MOD; }
lld mul(long long a, long long b) { return ((a % MOD) * (b % MOD)) % MOD; }
lld sub(long long a, long long b) {
  lld ans = ((a % MOD - b % MOD)) % MOD;
  if (ans < 0)
    ans += MOD;
  return ans;
}
lld gcd(lld a, lld b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
void MAIN(lld i, lld t);
int get() {
  lld t;
  cin >> t;
  ;
  return t;
}
template <class T> int logd(T name) {
  cout << name << endl;
  return 0;
}
void test(int t) {
  for (lld i = 1; i <= t; i++) {
    MAIN(i, t);
    if (shouldendl)
      cout << endl;
  }
}
lld power(lld x, lld y) {
  lld res = 1;
  x = x % MOD;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    y = y >> 1;
    x = (x * x) % MOD;
  }
  return res;
}
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {
  return {l.first + r.first, l.second + r.second};
}
#define all(v) (v).begin(), (v).end()
lld popcount(lld x) { return __builtin_popcountll(x); }
lld lcm(lld a, lld b) { return (a * b) / gcd(a, b); }
template <class T> bool input(vector<T> &v, lld n = -1) {
  assert(v.size() != 0);
  if (n == -1)
    n = v.size();
  for (auto &i : v)
    cin >> i;
  return 0;
}
template <class T> bool print(vector<T> v, lld l = 0, lld r = -1) {
  if (r == -1)
    r = v.size();
  for (int i = l; i < r; i++)
    cout << v[i] << " ";
  return 0;
}
// Observation, binary_search, dfs on strings, simplify the problem
// Observe and ELIMINATE
lld sum;
lld n;
lld dp[2001];
lld solve(lld temp) {
  if (temp > sum)
    return 0;
  if (temp == sum)
    return 1;
  if (dp[temp] != -1)
    return dp[temp];
  lld p = 0;
  for (int j = 3; j <= sum; j++) {
    p = add(p, solve(temp + j));
  }
  return dp[temp] = p;
}
void MAIN(lld current_test_case, lld total_test_cases) {

  cin >> sum;
  lld ans = 0;
  memset(dp, (lld)-1, sizeof(dp));
  ans = solve(0LL);

  cout << ans;
}
int main() {

  SPEED;
#ifndef ONLINE_JUDGE
  fileopen
#endif
      test(1);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mtv(kit) cout << #kit << " - " << kit << "\\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (i = a; i < b; i++)
#define pii pair<ll, ll>
#define all(x) x.begin(), x.end()
#define nl "\\n"
#define ump unordered_map

ll a[900][2002], mod = 1e9 + 7;
ll s;

ll f(ll in, ll su) {
  if (su < 0)
    return 0;
  if (su == 0)
    return 1;
  if (a[in][su] != -1) {
    return a[in][su];
  }
  ll ans = 0;
  for (ll i = 3; i <= min(s, su); i++) {
    ans += f(in + 1, su - i);
    ans %= mod;
  }
  return a[in][su] = ans;
}
void doit() {
  cin >> s;
  memset(a, -1, sizeof(a));
  cout << f(0, s) << nl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin >> t;
  for (ll i = 1; i <= t; i++) {
    doit();
  }
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mtv(kit) cout << #kit << " - " << kit << "\\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (i = a; i < b; i++)
#define pii pair<ll, ll>
#define all(x) x.begin(), x.end()
#define nl "\\n"
#define ump unordered_map

ll a[2002], mod = 1e9 + 7;
ll s;

ll f(ll su) {
  if (su < 0)
    return 0;
  if (su == 0)
    return 1;
  if (a[su] != -1) {
    return a[su];
  }
  ll ans = 0;
  for (ll i = 3; i <= su; i++) {
    ans += f(su - i);
    ans %= mod;
  }
  return a[su] = ans;
}
void doit() {
  cin >> s;
  memset(a, -1, sizeof(a));
  cout << f(s) << nl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin >> t;
  for (ll i = 1; i <= t; i++) {
    doit();
  }
}