def main():
    n, k = map(int, input().split())
    a = [int(input()) for _ in range(n)]
    b = [0]*(300010)
    dp = [0]*(n)
    for i in range(n):
        maxi = 0
        if len(b[max(0, a[i]-k):min(a[i]+k, n)]) != 0:
            maxi = max(b[max(0, a[i]-k):min(a[i]+k, n)+1])
        dp[i] = maxi + 1
        b[a[i]] = max(b[a[i]], dp[i])
    print(max(dp))
                
        
if __name__ == '__main__':
    main()