/// Author: Raiz
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#ifndef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#define int long long // Don't forget!!
#define __Lek_Raiz \
ios_base::sync_with_stdio(0); \
cin.tie(nullptr); \
cout.tie(nullptr)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ll long long
#define str string
#define pb push_back
#define pf push_front
#define ep emplace_back
#define pii pair<int, int>
#define FOR0(i, n) for (int i = 0; i < n; ++i)
#define FOR1(i, n) for (int i = 1; i <= n; ++i)
/// #define size(x) (int)x.size()
#define rs(x) resize(x)
#define vi vector<int>
#define input1(v) \
for (int i = 1; i <= n; ++i) \
cin >> v[i]
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/// priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
const int sz = 1e4 + 31; // hmm... RunTime error?
const int LOG = 63;
const int sz2 = 1e3 + 31;
const int MOD = 1e9 + 7;
const int INF = 1e18;
// cd Documents && cd Cpp && g++ main.cpp -o main && ./main
// variables:
int n, x;
vi v, LIS;
void solve()
{
cin >> n >> x;
v.rs(n + 1);
for (int i = 1; i <= n; ++i)
{
cin >> v[i];
if (lower_bound(all(LIS), v[i]) == LIS.end())
{
LIS.ep(v[i]);
}
else
{
LIS[lower_bound(all(LIS), v[i]) - LIS.begin()] = v[i];
}
}
if (x == 0)
{
cout << (int)LIS.size() << "\n";
return;
}
if ((n <= 50 && x <= 50) || (n <= 1000))
{
auto check1 = [&](int l, int r, int mid) -> int
{
vi a = v, LIS1;
for (int i = l; i <= r; ++i)
{
a[i] += mid;
}
for (int i = 1; i <= n; ++i)
{
if (lower_bound(all(LIS1), a[i]) == LIS1.end())
{
LIS1.ep(a[i]);
}
else
{
LIS1[lower_bound(all(LIS1), a[i]) - LIS1.begin()] = a[i];
}
}
return (int)LIS1.size();
};
int BEST_ANS = (int)LIS.size();
for (int i = 1; i <= n; ++i)
{
for (int j = i + 1; j <= n; ++j)
{
int l = -x, r = x, mid = 0;
while (l <= r)
{
mid = (l + r) >> 1;
int ANS = check1(i, j, mid);
if (ANS > BEST_ANS)
{
BEST_ANS = ANS;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
}
}
cout << BEST_ANS << "\n";
return;
}
}
signed main()
{
__Lek_Raiz;
// freopen("bcount.in", "r", stdin);
// freopen("bcount.out" , "w", stdout);
// sieve();
int t = 1;
/// cin >> t;
while (t-- > 0)
{
solve();
}
}
/*
..... .................... ....... ........ .....
.+@@* .-@@@@@@@@@@@@@@@@@+ =%@%-. ..:*%@@@=... =%@%:.
.+@@* .-@@@%%%%%%%%%%%%%%+ =%@%-. .+%@@@*-.. =%@%:
.+@@* .-@@#:............... =%@%-. ..=#%@@#=:... =%@%:
.+@@* .-@@#:. =%@%-. .-*%@@%*-.... =%@%:
.+@@* .-@@%#*************= =%@@#**%@@@#=... =%@%:
.+@@* .-@@@@@@@@@@@@@@@@@* =%@@@@@@@@%+:. =%@%:
.+@@* .-@@#:.............. =%@%- .+%@@@%-.. =%@%:
.+@@* .-@@#:. =%@%-. ...:*@@@%*:.. =%@%:
.+@@#::::::::::::::..=@@#-:::::::::::::: =%@%-... ..-#@@@#=. =%@%:
.+@@@@@@@@@@@@@@@@%-.=@@@@@@@@@@@@@@@@@* =%@%-... .:=%@@%*-. =%@%:
.-****************+:.:*****************-. :+*+:. .-+***=.. -+*+.
*/
//