#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
using ll = long long;
typedef pair<int, int> pii;
typedef unsigned long long ul;

const int mn = 3005;
const int mod = 998244353;

int n, K;
ll d[mn][mn];


ll dp(int remain_number, int need_cnt) {
	ll &ans = d[remain_number][need_cnt];
	if (remain_number < need_cnt) return 0;
	if (ans != -1) return ans;
	if (remain_number == 0 && need_cnt == 0) return ans = 1;
	ans = 0;
	if (need_cnt == 0 || remain_number == 0) return ans = 0;
	// get_one
	assert(remain_number >= 0 && need_cnt >= 0);
	ans = dp(remain_number - 1, need_cnt - 1);
	// get_small_one
	ans += dp(remain_number, need_cnt * 2);
	ans %= mod;
	//printf("%d %d %lld\n", remain_number, need_cnt, ans);
	return ans;
}

int main() {
	//cin.sync_with_stdio(0);
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
	//freopen("../2.txt", "w", stdout);

	auto st = chrono::system_clock::now();
#endif

	memset(d, -1, sizeof d);

	scanf("%d%d", &n, &K);
	printf("%lld\n", dp(n, K));


#ifdef LOCAL
	auto ed = chrono::system_clock::now();
	auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(ed - st);
	std::cerr << "cost time " << diff.count() << "ms." << std::endl;
#endif
	return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

struct E {
  int l = INT32_MAX, h = INT32_MIN;
};

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  v(E) es(N);
  F0R(i, N) {
    int x, c; cin >> x >> c;
    c--;
    chmin(es[c].l, x);
    chmax(es[c].h, x);
  }
  ll lx = 0, lt = 0;
  ll rx = 0, rt = 0;
  F0R(c, N) {
    auto [l, r] = es[c];
    if (l == INT32_MAX) continue;
    ll rx2 = es[c].h, lx2 = es[c].l;
    ll rt2 = min(lt + abs(lx - l) + abs(l - r), rt + abs(rx - l) + abs(l - r));
    ll lt2 = min(lt + abs(lx - r) + abs(r - l), rt + abs(rx - r) + abs(r - l));

    lx = lx2; rx = rx2;
    lt = lt2; rt = rt2;
  }
  cout << min(lt+abs(lx), rt+abs(rx)) << newl;
}
#endif
