JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom.

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $[1, 10^3]$.

JATC wonders what is the greatest number of elements he can erase?


-----Input-----

The first line of the input contains a single integer $n$ ($1 \le n \le 100$) — the number of elements in the array.

The second line of the input contains $n$ integers $a_i$ ($1 \le a_1<a_2<\dots<a_n \le 10^3$) — the array written by Giraffe.


-----Output-----

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print $0$.


-----Examples-----
Input
6
1 3 4 5 6 9

Output
2
Input
3
998 999 1000

Output
2
Input
5
1 2 3 4 5

Output
4


-----Note-----

In the first example, JATC can erase the third and fourth elements, leaving the array $[1, 3, \_, \_, 6, 9]$. As you can see, there is only one way to fill in the blanks.

In the second example, JATC can erase the second and the third elements. The array will become $[998, \_, \_]$. Because all the elements are less than or equal to $1000$, the array is still can be restored. Note, that he can't erase the first $2$ elements.

In the third example, JATC can erase the first $4$ elements. Since all the elements are greater than or equal to $1$, Giraffe can still restore the array. Note, that he can't erase the last $4$ elements.

Difficulty: EASY
Tags: Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = [0] + sorted(list(map(int, input().split()))) + [1001]
count = 0
ans = 0
for i in range(0, len(a) - 1):
	if a[i + 1] - a[i] == 1:
		count += 1
	else:
		count = 0
	ans = max(count - 1, ans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = 0
for i in range(n):
	if a[i] == 1:
		xm = 2
	else:
		xm = 1
	for j in range(i + 1, n):
		if a[j] - a[j - 1] == 1:
			xm += 1
			if a[j] == 1000:
				xm += 1
		else:
			break
	x = max(x, xm - 2)
print(x)


x = int(input())
arr = [int(x) for x in input().split()]
ans = 0
j = 0
count = 0
i = 1
while i < x - 1:
	count = 0
	if arr[i - 1] == arr[i] - 1:
		if arr[i - 1] == 1:
			count = count + 1
		j = i
		while arr[j] - 1 == arr[j - 1]:
			if arr[j] == 1000:
				count = count + 1
			count = count + 1
			if j == x - 1:
				break
			j = j + 1
	if count >= 2:
		i = j
		if count > ans:
			ans = count - 1
	else:
		i += 1
if x == 1000:
	ans = 0
if ans == 0 and x > 1:
	if arr[0] == 1 and arr[1] == 2 or (arr[x - 2] == 999 and arr[x - 1] == 1000):
		ans = 1
print(ans)


n = int(input())
a = list(map(int, input().strip().split()))
a.append(0)
a.append(1001)
b = sorted(a)
cnt = 0
ans = 0
for i in range(len(b)):
	if i > 0 and b[i] == b[i - 1] + 1:
		cnt += 1
		if cnt - 2 > ans:
			ans = cnt - 2
	else:
		cnt = 1
print(ans)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(''.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1
for _ in range(t):
	n = ii()
	a = li()
	cur = 0
	if a[0] == 1:
		cur = 1
	mx = 0
	for i in range(1, n):
		if a[i] == a[i - 1] + 1:
			cur += 1
		else:
			mx = max(mx, cur - 1)
			cur = 0
	if cur > 0:
		if a[-1] == 1000:
			mx = max(mx, cur)
		else:
			mx = max(mx, cur - 1)
	print(mx)


n = int(input())
a = [0] + [int(x) for x in input().split()] + [1001]
md = 0
td = 0
for i in range(1, n + 1):
	if a[i] - a[i - 1] == 1 and a[i + 1] - a[i] == 1:
		td += 1
		md = max(md, td)
	else:
		td = 0
print(md)


from sys import stdin, stdout
n = int(stdin.readline())
ary = list(map(int, stdin.readline().split()))
ary = [0] + ary + [1001]
ans = 0
for i in range(1, n + 1):
	if ary[i] - ary[i - 1] == 1:
		for j in range(i + 1, n + 2):
			if ary[j] - ary[j - 1] != 1:
				j = j - 1
				break
		ans = max(ans, j - i)
stdout.write('{}'.format(ans))


n = int(input())
a = list(map(int, input().split()))
d = 0
for i in range(n):
	for j in range(i + 1, n):
		if a[j] - a[i] == j - i:
			tmp = j - i - 1
			if i == 0 and a[i] == 1 or (j == n - 1 and a[j] == 1000):
				tmp += 1
			d = max(d, tmp)
print(d)


n = int(input())
l = [int(s) for s in input().split()]
s = []
curr = set()
for i in range(n - 1):
	if l[i + 1] - l[i] == 1:
		curr.add(l[i])
		curr.add(l[i + 1])
	elif len(curr) != 0:
		if min(list(curr)) == 1:
			curr.add(0)
		s.append(curr)
		curr = set()
if len(curr) != 0:
	if max(list(curr)) == 1000:
		curr.add(1001)
	if min(list(curr)) == 1:
		curr.add(0)
	s.append(curr)
ans = 0
for i in s:
	if len(i) - 2 > ans:
		ans = len(i) - 2
print(ans)


n = int(input())
arr = [int(x) for x in input().strip().split()]
maximum = 1
count = 1
last = arr[0]
consec = []
notconsec = set()
cur = [arr[0]]
for i in range(1, len(arr)):
	if arr[i] == last + 1:
		count += 1
		cur.append(arr[i])
	else:
		if count >= 2:
			consec.append(cur)
		notconsec.add(arr[i] - last + 1)
		count = 1
		cur = [arr[i]]
	last = arr[i]
if count >= 2:
	consec.append(cur)
ans = 0
for i in consec:
	temp = len(i) - 2
	if i[0] == 1:
		temp += 1
	if i[-1] == 1000:
		temp += 1
	ans = max(ans, temp)
print(ans)


n = int(input())
s = [int(x) for x in input().split()]
maxi = 0
i = 1
while i < len(s):
	ans = 0
	if s[i] == s[i - 1] + 1:
		if s[i - 1] == 1:
			ans += 1
		while i < len(s) - 1 and s[i] == s[i + 1] - 1:
			ans += 1
			i += 1
		if s[i] == 1000:
			ans += 1
	maxi = max(maxi, ans)
	i += 1
print(maxi)


from collections import Counter

def solution(n, arr):
	arr = [0] + arr
	arr.append(1001)
	best = 0
	count = 0
	for (ind, val) in enumerate(arr[:-2]):
		if val + 1 == arr[ind + 1] and val + 2 == arr[ind + 2]:
			count += 1
		else:
			if best < count:
				best = count
			count = 0
	print(max(best, count))
n = [int(val) for val in input().split()][0]
arr = [int(val) for val in input().split()]
solution(n, arr)


n = int(input())
a = list(map(int, input().split()))
ans = []
l = [a[0]]
for i in range(1, n):
	if a[i] != a[i - 1] + 1:
		if len(ans) < len(l):
			ans = l
		l = []
	l.append(a[i])
if len(ans) < len(l) or (len(ans) == len(l) and l[-1] == 1000):
	ans = l
if ans != [] and ans[0] != 1:
	ans.pop(0)
if ans != [] and ans[-1] != 1000:
	ans.pop()
print(len(ans))


n = int(input())
l = list(map(int, input().split()))
l = [0] + l + [1001]
k = 0
ma = 0
for i in range(1, n + 1):
	if l[i + 1] - 1 == l[i] == l[i - 1] + 1:
		k += 1
	else:
		ma = max(ma, k)
		k = 0
ma = max(ma, k)
print(ma)


n = int(input())
arr = [0] + list(map(int, input().split())) + [1001]
ans = 0
for i in range(n + 2):
	e = 0
	s = arr[i]
	for j in range(i + 1, n + 2):
		if arr[j] == s + 1:
			s = arr[j]
			e += 1
		else:
			break
	ans = max(e - 1, ans)
print(ans)


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
max_ans = 0
ans = 0
for i in range(1, len(a) - 1):
	if a[i] == a[i - 1] + 1 and a[i] == a[i + 1] - 1:
		ans += 1
	else:
		max_ans = max(ans, max_ans)
		ans = 0
print(max(max_ans, ans))


n = int(input())
a = [int(x) for x in input().split()]
a = [0] + a + [1001]
max_res = 1
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if a[j] - a[i] == j - i:
			max_res = max(max_res, j - i)
print(max_res - 1)


(n,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
highscore = 0
if n >= 3:
	for i in range(0, n - 1):
		count = -1
		for j in range(i, n - 1):
			if A[j] + 1 == A[j + 1]:
				count += 1
			else:
				break
		if count > highscore:
			highscore = count
b = 0
e = 0
while A[b] == b + 1:
	b += 1
	if b == n:
		break
while A[n - 1 - e] == 1000 - e:
	e += 1
	if e == n:
		break
print(max(b - 1, e - 1, highscore, 0))


from typing import Dict, List, Tuple

def input_lst() -> List[int]:
	return [int(x) for x in input().split()]

def print_out(res: List[int]):
	print(' '.join([str(x) for x in res]))

def main():
	(n,) = (int(x) for x in input().split())
	a = input_lst()
	l = 0
	l_max = 0
	if a[0] == 1:
		l += 1
	for i in range(n - 1):
		if a[i + 1] - a[i] == 1:
			l += 1
		elif l > 0:
			l_max = max(l, l_max)
			l = 0
	if l > 0:
		if a[-1] == 1000:
			l += 1
		l_max = max(l, l_max)
	print(max(l_max - 1, 0))

def __starting_point():
	main()
__starting_point()


x = input()
y = input()
z = y.split()
maxi = 0
t = 0
count = 0
if x == '1':
	print('0')
else:
	while t < int(x) - 1:
		if int(z[t + 1]) - int(z[t]) == 1:
			count += 1
			if z[t] == '1':
				count += 1
			if z[t + 1] == '1000':
				count += 1
			a = count
		else:
			a = count
			count = 0
		t += 1
		if a != 0:
			a -= 1
		if maxi < a:
			maxi = a
	print(maxi)


n = int(input())
lst = list(map(int, input().split()))
(res, e) = (0, 0)
if lst[0] == 1:
	e = 1
for i in range(1, n):
	if lst[i] - lst[i - 1] == 1:
		e += 1
	else:
		if res < e:
			res = e - 1
		e = 0
if res < e:
	if lst[n - 1] == 1000:
		res = e
	else:
		res = e - 1
print(res)


def b():
	arrlen = int(input())
	arr = list(map(int, input().split()))
	arrlen += 1
	arr.append(1001)
	first = 0
	lon = 1
	ans = 0
	for i in range(0, arrlen):
		if arr[i] == first + 1:
			lon += 1
			first += 1
		else:
			ans = max(ans, lon - 2)
			lon = 1
			first = arr[i]
	ans = max(ans, lon - 2)
	print(ans)
b()


n = int(input())
a = [0] + [int(i) for i in input().split()] + [1001]
ans = 0
if n == 1:
	print(0)
else:
	t = 0
	for i in range(1, n + 1):
		if a[i + 1] - a[i - 1] == 2:
			t += 1
		else:
			ans = max(ans, t)
			t = 0
	ans = max(ans, t)
	print(ans)


def prank():
	max_consec = 0
	run_consec = 0
	num = int(input())
	a = input().split()
	i = 1
	if int(a[0]) == 1:
		run_consec += 1
	for i in range(1, num):
		if int(a[i]) - int(a[i - 1]) == 1:
			run_consec += 1
		else:
			max_consec = max(max_consec, run_consec)
			run_consec = 0
	max_consec = max(max_consec, run_consec)
	if int(a[num - 1]) == 1000 and run_consec != 0:
		run_consec += 1
		max_consec = max(max_consec, run_consec)
	if max_consec == 0:
		print(0)
	else:
		print(max_consec - 1)
prank()


n = int(input())
b = list(map(int, input().split()))
mx = 0
cn = 0
for i in range(n - 1):
	if b[i] + 1 == b[i + 1]:
		cn += 1
		if b[i] == 1 or b[i + 1] == 1000:
			cn += 1
	else:
		cn = 0
	mx = max(mx, cn)
if mx != 0:
	print(mx - 1)
else:
	print(0)


n = int(input())
s = input().split()
l = [0] + [int(s[i]) for i in range(n)] + [1001]
maxlen = 0
prev = 0
cnt = 1
for i in range(1, n + 2):
	if prev == l[i] - 1:
		cnt += 1
	else:
		maxlen = max(maxlen, cnt - 2)
		cnt = 1
	prev = l[i]
maxlen = max(maxlen, cnt - 2)
print(maxlen)


n = int(input())
numbers = input().split()
counter = [0] * 1001
cnt = 0
save_i = -1
max_points = 0
for i in range(n):
	if i == 0:
		if 1 - int(numbers[i]) == 0:
			if i < n - 1 and int(numbers[i + 1]) - int(numbers[i]) == 1:
				if save_i == i - 1:
					counter[cnt] += 1
					max_points = max(counter[cnt], max_points)
					save_i += 1
				else:
					cnt += 1
					counter[cnt] += 1
					max_points = max(counter[cnt], max_points)
					save_i = i
	elif i < n - 1:
		if int(numbers[i]) - int(numbers[i - 1]) == 1 and int(numbers[i + 1]) - int(numbers[i]) == 1:
			if save_i == i - 1:
				counter[cnt] += 1
				max_points = max(counter[cnt], max_points)
				save_i += 1
			else:
				cnt += 1
				counter[cnt] += 1
				max_points = max(counter[cnt], max_points)
				save_i = i
	elif i == n - 1 and 1000 - int(numbers[i]) == 0 and (int(numbers[i]) - int(numbers[i - 1]) == 1):
		if save_i == i - 1:
			counter[cnt] += 1
			max_points = max(counter[cnt], max_points)
			save_i += 1
		else:
			cnt += 1
			counter[cnt] += 1
			max_points = max(counter[cnt], max_points)
			save_i = i
print(max_points)


n = int(input())
a = [0]
a.extend(list(map(int, input().split())))
a.append(1001)
longest = 0
i = 0
while i < len(a):
	j = i + 1
	while j < len(a) and a[j - 1] + 1 == a[j]:
		j += 1
	current = j - i - 2
	longest = max(longest, current)
	i = j
print(longest)


import sys
input_file = sys.stdin
n = int(input_file.readline())
lst = [0] + list((int(i) for i in input_file.readline().split())) + [1001]
maxi = 1
ans = 1
for i in range(1, len(lst)):
	if lst[i] == lst[i - 1] + 1:
		ans += 1
	else:
		maxi = max(maxi, ans)
		ans = 1
maxi = max(maxi, ans)
print(max(maxi - 2, 0))


def test_1():
	import math
	from collections import Counter
	n = list(map(int, input().split(' ')))[0]
	data = list(map(int, input().split(' ')))
	count_1 = 0
	count_2 = 0
	data.insert(0, 0)
	data.append(1001)
	for i in range(1, n + 1):
		if data[i + 1] - data[i - 1] == 2:
			count_1 += 1
		else:
			count_2 = max(count_2, count_1)
			count_1 = 0
	count_2 = max(count_2, count_1)
	print(count_2)
test_1()


n = int(input())
arr = list(map(int, input().split()))
max1 = 0
for i in range(1, n):
	if arr[i] - arr[i - 1] == 1:
		count = 0
		j = i - 1
		i += 1
		if i != n:
			while arr[i] - arr[i - 1] == 1:
				count += 1
				i += 1
				if i == n:
					break
		k = i - 1
		if arr[j] == 1 or arr[k] == 1000:
			count += 1
		if max1 < count:
			max1 = count
print(max1)


from sys import stdin, stdout
from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial
n = int(stdin.readline())
vl = list(map(int, stdin.readline().split()))
ans = 0
for i in range(n):
	cnt = 0
	while i + cnt < n and vl[i + cnt] == vl[i] + cnt:
		cnt += 1
	ans = max(ans, cnt - 2)
cnt1 = 0
while cnt1 < n and vl[cnt1] == cnt1 + 1:
	cnt1 += 1
cnt2 = 0
while cnt2 < n and vl[n - 1 - cnt2] == 10 ** 3 - cnt2:
	cnt2 += 1
ans = max(ans, max(cnt1, cnt2) - 1)
stdout.write(str(ans))


N = int(input())
A = list(map(int, input().strip().split(' ')))
N = len(A)

def length(points):
	return points[1] - points[0] + 1
longest = [-1, -1]
temp = [-1, -1]
counting = 0
for idx in range(1, N):
	if A[idx - 1] + 1 == A[idx]:
		if counting == 0:
			temp[0] = idx - 1
			counting = 1
		temp[1] = idx
	else:
		counting = 0
	if length(temp) > length(longest):
		longest = temp[:]
	elif length(temp) == length(longest) and A[temp[1]] == 1000:
		longest = temp[:]
if A[longest[0]] == 1:
	print(length(longest) - 1)
elif A[longest[1]] == 1000:
	print(length(longest) - 1)
elif length(longest) <= 2:
	print(0)
else:
	print(length(longest) - 2)


n = int(input())
list1 = list(map(int, input().split()))
c = 0
s = 0
ele = list1[0]
list2 = [ele]
for i in range(1, n):
	if list1[i] == ele + 1:
		list2.append(list1[i])
		ele = list1[i]
	else:
		ele = list1[i]
		if list2:
			c = len(list2) - 2
			if c < 0:
				c = 0
				list2 = [ele]
				continue
			if list2[0] == 1:
				c += 1
			if list2[-1] == 1000:
				c += 1
			if c > s:
				s = c
		list2 = [ele]
if list2:
	f = 0
	c = len(list2) - 2
	if c < 0:
		c = 0
		list2 = [ele]
		f = 1
	if f == 0:
		if list2[0] == 1:
			c += 1
		if list2[-1] == 1000:
			c += 1
	if c > s:
		s = c
print(s)


n = int(input())
a = list(map(int, input().split()))
(s, e) = (0, 1)
mmax = 0
while e < n:
	while e < n and a[e] == a[e - 1] + 1:
		e += 1
	cur = e - s - 2
	if a[e - 1] == 1000 or a[s] == 1:
		cur += 1
	mmax = max(mmax, cur)
	(s, e) = (e, e + 1)
print(mmax)


(l, inp, maxseq, currseq) = (int(input()), [0] + list(map(int, input().split(' '))) + [1001, 5000], 0, [])
for i in range(l + 2):
	if inp[i] + 1 == inp[i + 1]:
		currseq.append(inp[i])
	else:
		(maxseq, currseq) = (max(maxseq, len(currseq)), [])
print(max(maxseq - 1, 0))


def fun():
	N = int(input())
	arr = list(map(int, input().split()))
	new_arr = [0]
	for i in arr:
		new_arr.append(i)
	new_arr.append(1001)
	ans = 0
	count = 0
	for i in range(1, N + 2):
		if new_arr[i] == 1 + new_arr[i - 1]:
			count += 1
		else:
			ans = max(ans, count)
			count = 0
	ans = max(ans, count)
	print(max(0, ans - 1))
fun()


n = int(input().strip())
c = [0] + [int(_) for _ in input().strip().split()] + [1001]
ans = 0
tempans = 0
for i in range(1, n + 1):
	if c[i - 1] + 1 == c[i] and c[i] + 1 == c[i + 1]:
		tempans += 1
		ans = max(tempans, ans)
	else:
		tempans = 0
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(0, n):
	for j in range(i + 1, n):
		if a[j] - a[i] == j - i:
			if a[j] == 1000 or (a[i] == 1 and (not (a[j] == 1000 and a[i] == 1))):
				ans = max(j - i, ans)
			if a[j] == 1000 and a[i] == 1:
				ans = 1000
			else:
				ans = max(j - i - 1, ans)
print(ans)


n = int(input())
A = []
A.append(0)
B = list(map(int, input().split()))
A = A + B
A.append(1001)
summ = 0
maxsumm = 0
for i in range(1, n + 1):
	if A[i] - A[i - 1] == 1 and A[i + 1] - A[i] == 1:
		summ += 1
		if summ > maxsumm:
			maxsumm = summ
	else:
		summ = 0
else:
	print(maxsumm)


n = int(input())
x = [0] + list(map(int, input().split())) + [1001]
ans = temp = 0
for i in range(n + 1):
	if x[i + 1] - x[i] == 1:
		temp += 1
	else:
		ans = max(ans, temp - 1)
		temp = 0
ans = max(ans, temp - 1)
print(ans)


import sys
import math
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
maxi = 0

def check(arr):
	for i in range(1, len(arr)):
		if arr[i] - arr[i - 1] != 1:
			return (False, 0)
	if arr[-1] == 1000 and arr[0] == 1:
		return (True, len(arr))
	if arr[-1] == 1000:
		return (True, len(arr) - 1)
	if arr[0] == 1:
		return (True, len(arr) - 1)
	return (True, len(arr) - 2)
for i in range(0, n):
	curr = 0
	for j in range(i, n):
		(flag, curr) = check(arr[i:j + 1])
		if flag:
			maxi = max(maxi, curr)
print(maxi)


n = input()
a = input().split()
a = [int(x) for x in a]
temp = 0
maxC = 0
for i in range(int(n) - 1):
	if n == 1:
		continue
	if i == 0:
		if a[i] == 1 and a[i + 1] == 2:
			temp += 1
			if maxC < temp:
				maxC = temp
		if a[i + 1] == 1000 and a[i] == 999:
			temp += 1
		if maxC < temp:
			maxC = temp
		continue
	if a[i + 1] == 1000 and a[i] == 999:
		temp += 1
		if maxC < temp:
			maxC = temp
	if a[i + 1] == a[i] + 1 and a[i - 1] == a[i] - 1:
		temp += 1
		if maxC < temp:
			maxC = temp
	else:
		temp = 0
print(maxC)


n = int(input())
a = list(map(int, input().split()))
a.append(1000000)
maxi = 0
last = a[0]
current = [a[0]]
l = 0
for i in range(n + 1):
	if a[i] - 1 == a[i - 1]:
		current.append(a[i])
	else:
		l = len(current)
		if current[0] != 1:
			l -= 1
		if current[-1] != 1000:
			l -= 1
		maxi = max(maxi, l)
		current = [a[i]]
print(maxi)


input()
a = [0] + [*map(int, input().split())] + [1001]
m = c = 0
for (x, y) in zip(a, a[1:]):
	if x + 1 == y:
		c += 1
		m = max(m, c - 1)
	else:
		c = 0
print(m)


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
mx = 0
for i in range(n + 2):
	j = i + 3
	while j <= n + 2:
		if a[i:j] == list(range(a[i], a[i] + j - i)):
			mx = max(mx, j - i - 2)
		j += 1
print(mx)


n = int(input())
m = list(map(int, input().split(' ')))
m.insert(n, 1001)
m.insert(0, 0)
count = 0
maxV = 0
for i in range(1, len(m) - 1):
	if m[i] == m[i - 1] + 1 and m[i] == m[i + 1] - 1:
		count += 1
		maxV = max(maxV, count)
	else:
		count = 0
print(maxV)


from math import sqrt

def main():
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	maxlen = 0
	i = 0
	while i < n:
		b = [a[i]]
		cnt = 1
		j = i + 1
		while j < n and a[j] - a[j - 1] == 1:
			b.append(a[j])
			j += 1
		cnt = len(b) - 2
		if b[0] == 1:
			cnt += 1
		if b[-1] == 1000:
			cnt += 1
		if cnt > maxlen:
			maxlen = cnt
		b = []
		i = j
	print(maxlen)
	return
main()


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
length = 0
f = False
c = 0
for i in range(1, n + 2):
	if a[i] == a[i - 1] + 1:
		if not f:
			f = True
			c = 0
		else:
			c += 1
	else:
		f = False
		length = max(length, c)
		c = 0
length = max(length, c)
print(length)


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
ans = 0
cnt = 1
for i in range(1, n + 2):
	if a[i] == a[i - 1] + 1:
		cnt += 1
		ans = max(ans, cnt - 2)
	else:
		cnt = 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.append(1001)
l = [0] + l
smax = 0
s = 1
for i in range(1, len(l)):
	if l[i] - l[i - 1] == 1:
		s = s + 1
		smax = max(s, smax)
	else:
		smax = max(s, smax)
		s = 1
print(max(0, smax - 2))


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	first = 1
	if a[0] == 1:
		for i in range(1, n):
			if a[i] == a[i - 1] + 1:
				first += 1
			else:
				break
	last = 1
	if a[n - 1] == 1000:
		for i in range(n - 2, -1, -1):
			if a[i] + 1 == a[i + 1]:
				last += 1
			else:
				break
	mid = 1
	maxx = 0
	for i in range(1, n):
		if a[i] == a[i - 1] + 1:
			mid += 1
			maxx = max(maxx, mid)
		else:
			mid = 1
	print(max(maxx - 2, first - 1, last - 1))
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


n = int(input())
a = list(map(int, input().split()))
c = -1
maxx = 0
if a[n - 1] == n or n == 1:
	maxx = n - 1
else:
	if a[1] == 2:
		c = 0
	for i in range(1, n - 1):
		if a[i] - 1 == a[i - 1]:
			c += 1
		else:
			if maxx < c:
				maxx = c
			c = -1
	if a[n - 2] + 1 == a[n - 1]:
		c += 1
	if a[n - 2] == 999:
		c = 0
		for i in range(n - 2, -1, -1):
			if a[i] + 1 == a[i + 1]:
				c += 1
			else:
				break
	if maxx < c:
		maxx = c
print(maxx)


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
res = 1
cur = 1
for i in range(n + 1):
	if a[i + 1] - a[i] == 1:
		cur += 1
	else:
		cur = 1
	res = max(res, cur)
print(max(0, res - 2))


n = int(input())
a = list(map(int, input().split()))
count = 0
c = 0
x = 0
y = 0
ans = 0
for i in range(n - 1):
	if c == 0:
		x = a[i]
	if a[i] == a[i + 1] - 1:
		c += 1
		y = a[i + 1]
	else:
		if y - x == c:
			count += c - 1
		if x == 1 and c != 0:
			count += 1
		ans = max(count, ans)
		count = 0
		c = 0
if c != 0:
	if y - x == c:
		count += c - 1
	if x == 1 or y == 1000:
		count += 1
	ans = max(count, ans)
	count = 0
print(ans)


import math
from decimal import Decimal
import heapq

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
a = [0] + a[:] + [1001]
tc = 0
ans = 0
for i in range(1, n + 2):
	if a[i] - a[i - 1] == 1:
		tc += 1
		if tc > ans:
			ans = tc - 1
	else:
		tc = 0
print(ans)


gcd = lambda a, b: gcd(b, a % b) if b else a

def main():
	n = int(input())
	arr = [0] + list(map(int, input().split())) + [1001]
	mx = 0
	for i in range(0, len(arr)):
		for j in range(i, len(arr)):
			if arr[i] - i == arr[j] - j:
				mx = max(mx, j - i - 1)
	print(mx)
main()


input()
x = 0
a = [int(i) for i in input().split()]
if len(a) == 1000:
	x = 1000
else:
	mm = 0
	(k, l) = (a[0], a[-1])
	for i in range(len(a) - 1):
		for j in range(i + 1, len(a)):
			if a[j] - a[i] == len(a[i:j]):
				mx = a[j] - a[i] - 1
				if mx >= mm:
					mm = mx
					k = a[i]
					l = a[j]
					if k == 1 or l == 1000:
						mm += 1
	x = mm
print(x)


a = int(input())
b = input().split()
k = 0
c = []
for i in range(a - 1):
	if int(b[i]) == 1:
		k += 1
	if int(b[i]) == int(b[i + 1]) - 1:
		if int(b[i + 1]) == 1000:
			k += 2
		else:
			k += 1
		if i == a - 2:
			k -= 1
			c.append(k)
	else:
		k -= 1
		c.append(k)
		k = 0
maxi = 0
for i in c:
	if maxi < i:
		maxi = i
print(maxi)


from sys import stdin, stdout
import collections
N = int(input())
arr = [int(x) for x in stdin.readline().split()]
head = -1
tail = -1
res = 0
for i in range(N):
	for j in range(i, N):
		if i == 0:
			head = 0
		else:
			head = arr[i - 1]
		if j == N - 1:
			tail = 1001
		else:
			tail = arr[j + 1]
		if tail - head == j - i + 2:
			res = max(res, j - i + 1)
print(res)


n = int(input())
l1 = list(map(int, input().split()))
C = 0
c = 0
s = l1[0]
if l1[0] == 1:
	c = 1
for i in range(1, n):
	if l1[i] == l1[i - 1] + 1:
		c = c + 1
	else:
		if c - 1 > C:
			C = c - 1
		c = 0
if l1[-1] == 1000:
	c += 1
if c - 1 > C:
	C = c - 1
print(C)


n = int(input())
arr = [0] + list(map(int, input().split())) + [1001]
count = 0
flag = 0
c = 0
for i in range(1, len(arr)):
	if arr[i] - arr[i - 1] == 1:
		if flag == 0:
			flag = 1
			c = 0
		else:
			c += 1
	else:
		flag = 0
		count = max(count, c)
		c = 0
count = max(count, c)
print(count)


n = int(input())
l = [0] + list(map(int, input().split())) + [1001]
answers = []
counter = 0
for i in range(1, n + 1):
	if l[i] - l[i - 1] == 1 and l[i] - l[i + 1] == -1:
		counter += 1
		continue
	answers.append(counter)
	counter = 0
answers.append(counter)
print(max(answers))


def eraseElement(arr):
	count = 0
	max_ = 0
	start = 0
	end = 0
	s = -1
	e = -1
	for i in range(1, len(arr)):
		if arr[i] == arr[i - 1] + 1:
			count += 1
			end = i
		else:
			start = i
			count = 0
		if end == len(arr) - 1 and arr[end] == 1000 and (max_ <= count):
			max_ = count
			s = start
			e = end
		elif max_ < count:
			max_ = count
			s = start
			e = end
	if max_ == 0:
		return 0
	elif len(arr) == 1000:
		return 1000
	elif s == 0 and arr[s] == 1 or (e == len(arr) - 1 and arr[e] == 1000):
		return max_
	else:
		return max_ - 1
n = int(input())
arr = list(map(int, input().split()))
print(eraseElement(arr))


n = int(input())
L = [0] + list(map(int, input().split())) + [1001]
c = 0
gm = 0
for i in range(0, n + 1):
	if L[i + 1] - L[i] == 1:
		c += 1
	else:
		c = 0
	gm = max(c - 1, gm)
print(gm)


n = int(input())
arr = list(map(int, input().strip().split()))
ans = []
for i in range(n):
	for j in range(i + 1, n):
		z = 0
		if arr[j] - arr[i] == j - i:
			z = j - i - 1
			if i == 0:
				if arr[i] == 1:
					z += 1
			elif arr[i] - arr[i - 1] == 1:
				z += 1
			if arr[j] == 1000:
				z += 1
		ans.append(z)
if ans == []:
	print(0)
else:
	print(max(ans))


def function2():
	remove = input()
	numbers = [int(x) for x in str(input()).split()]
	(answer, L) = (0, 0)
	if len(numbers) == 1:
		print(0)
		return

	def find_increasing_interval(start):
		end = start
		while end < len(numbers) - 1 and numbers[end] + 1 == numbers[end + 1]:
			end += 1
		return end
	while L < len(numbers):
		R = find_increasing_interval(L)
		if R == L:
			L += 1
			continue
		if L == 0 and numbers[L] == 1:
			answer = max(answer, R - L)
		elif R == len(numbers) - 1 and numbers[R] == 1000:
			answer = max(answer, R - L)
		else:
			answer = max(answer, R - L + 1 - 2)
		L = R + 1
	print(answer)
function2()


n = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
	flag_1 = True
else:
	flag_1 = False
if array[n - 1] == 1000:
	flag_1000 = True
else:
	flag_1000 = False
max = 0
ans = 0
controller = 0
sequence = False
for number in array:
	if number == controller + 1:
		if sequence:
			ans += 1
		else:
			sequence = True
		if sequence and number == 1000:
			ans += 1
	else:
		sequence = False
		ans = 0
	controller = number
	if max < ans:
		max = ans
print(max)


n = int(input())
A = [0] + list(map(int, input().split())) + [1001]
c = 0
ans = 0
for i in range(1, n + 1):
	if A[i] - 1 == A[i - 1] and A[i] + 1 == A[i + 1]:
		c += 1
	else:
		c = 0
	ans = max(ans, c)
print(ans)


n = int(input())
s = input().split()
ary = []
for i in range(n):
	ary.append(int(s[i]))
ary.append(-1)
cnt = 1
maxi = 0
for i in range(1, n + 1):
	if ary[i] == ary[i - 1] + 1:
		cnt += 1
	else:
		if cnt > 1 and (ary[i - cnt] == 1 or ary[i - 1] == 1000):
			if maxi < cnt - 1:
				maxi = cnt - 1
		elif cnt > 2:
			if maxi < cnt - 2:
				maxi = cnt - 2
		cnt = 1
print(maxi)


n = int(input())
vetor = list(map(int, input().split()))
vetor = [0] + vetor + [10 ** 3 + 1]
resposta = 0
cont = 1
for i in range(n + 1):
	if vetor[i + 1] - vetor[i] == 1:
		cont += 1
		resposta = max(resposta, cont)
	else:
		cont = 1
if resposta > 2:
	print(resposta - 2)
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
maiorSeq = 0
for i in range(0, len(l) - 1, 1):
	inicio = i
	fim = i
	cont = 0
	for j in range(i, len(l) - 1, 1):
		if l[j] + 1 == l[j + 1]:
			cont = cont + 1
		else:
			fim = j
			break
	if inicio == fim:
		fim = len(l) - 1
	if l[inicio] == 1 and cont != 0:
		cont = cont + 1
	if l[fim] == 1000 and cont != 0:
		cont = cont + 1
	if maiorSeq < cont:
		maiorSeq = cont
if len(l) == 1 or maiorSeq == 0:
	maiorSeq = 0
else:
	maiorSeq = maiorSeq - 1
print(maiorSeq)


n = int(input())
a = list(map(int, input().split()))
counts = [0]
if n == 1:
	pass
else:
	count = 0
	for i in range(n):
		if i == 0:
			if a[i] == 1 and a[i + 1] - a[i] == 1:
				count += 1
		elif i == n - 1:
			if a[i] == 1000 and a[i] - a[i - 1] == 1:
				count += 1
		elif a[i] - a[i - 1] == 1 and a[i + 1] - a[i] == 1:
			count += 1
		else:
			if count:
				counts.append(count)
			count = 0
	counts.append(count)
print(max(counts))


n = int(input())
a = list(map(int, input().split()))
c = []
d = []
for i in range(0, n - 1):
	if a[i] + 1 == a[i + 1]:
		c.append(a[i])
	else:
		c.append(a[i])
		d.append(c)
		del c
		c = []
if a[n - 2] + 1 == a[n - 1]:
	c.append(a[n - 1])
d.append(c)
s = []
for i in range(0, len(d)):
	if len(d[i]) == 0:
		t = 0
	elif d[i][0] == 1 or d[i][len(d[i]) - 1] == 1000:
		s.append(len(d[i]) - 1)
	else:
		s.append(len(d[i]) - 2)
if len(s) == 0 or max(s) < 0:
	print(0)
else:
	print(max(s))


n = int(input())
arr = [int(x) for x in input().split()]
arr.append(1001)
aux = 0
atam = 1
maxtam = 0
for i in range(n + 1):
	if arr[i] == aux + 1:
		atam += 1
		aux += 1
	else:
		maxtam = max(atam - 2, maxtam)
		atam = 1
		aux = arr[i]
maxtam = max(atam - 2, maxtam)
print(maxtam)


n = int(input())
l = list(map(int, input().split()))
l1 = [0]
for i in l:
	l1.append(i)
l1.append(1001)
ans = 0
mx = 0
flag = 0
for i in range(0, n + 1):
	if l1[i] + 1 == l1[i + 1]:
		if flag == 1:
			mx += 1
			ans = max(ans, mx)
		flag = 1
	else:
		flag = 0
		mx = 0
if n == 1000:
	ans -= 1
print(ans)


import filecmp
import os
import sys
FILE_IO = True if os.getenv('FILE_TEST') is not None else False
if FILE_IO:
	input_stream = open('input_test.txt')
	sys.stdout = open('current_output.txt', 'w')
else:
	input_stream = sys.stdin
n = int(input_stream.readline().split()[0])
count = 0
max_c = 0
if n in [0, 1]:
	print(0)
else:
	input_line = input_stream.readline().split()
	input_list = list(map(int, input_line))
	for i in range(len(input_list)):
		cond_1 = i - 1 >= 0 and input_list[i] - input_list[i - 1] == 1
		cond_2 = i + 1 < len(input_list) and input_list[i + 1] - input_list[i] == 1
		if cond_1 and cond_2:
			count += 1
		else:
			if max_c < count:
				max_c = count
			count = 0
		if cond_1 and i == 1 and (input_list[i] == 2):
			count += 1
		if cond_2 and i == len(input_list) - 2 and (input_list[i] == 999):
			count += 1
	if max_c < count:
		max_c = count
	print(max_c)
if FILE_IO:
	assert filecmp.cmp('current_output.txt', 'expected_output.txt', shallow=False) == True


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	ans = 0
	f = False
	c = 0
	if a[1] == 2:
		ans = 1
		c = 1
		f = True
	for i in range(1, n - 1):
		if a[i + 1] - a[i - 1] == 2:
			if f:
				c += 1
				ans = max(ans, c)
			else:
				f = True
				c = 1
				ans = max(ans, c)
		else:
			c = 0
			f = False
	if f and n >= 2 and (a[n - 2] == 999):
		c += 1
	elif n >= 2 and a[n - 2] == 999:
		c = 1
	print(max(ans, c))


def aPrank(n, arr):
	con = 1
	maxn = 1
	for i in range(1, n + 2):
		pos = arr[i - 1] + 1
		if arr[i] == pos:
			con = con + 1
			maxn = max(con, maxn)
		else:
			con = 1
	return max(0, maxn - 2)
n = int(input())
nmax = 1 + 1000
arr = [0] + [int(c) for c in input().split()]
arr.append(nmax)
print(aPrank(n, arr))


n = int(input())
a = list(map(int, input().split(' ')))
a = [0] + a + [1001]
if n == 1:
	print(0)
else:
	m = 0
	counter = 0
	for i in range(len(a) - 1):
		if a[i + 1] - a[i] == 1:
			counter += 1
			if counter > m:
				m = counter
		else:
			counter = 0
	print(max(m - 1, 0))


n = int(input())
arr = [0] + [int(z) for z in input().split()] + [1001]
if n == 1:
	print(0)
	exit()
p = 1
finl = 0
while p < n + 1:
	l = 0
	for i in range(p, n + 1):
		if arr[i] == arr[i - 1] + 1 and arr[i] == arr[i + 1] - 1:
			l += 1
		else:
			break
	p += 1
	finl = max(finl, l)
print(finl)


n = int(input())
a = list(map(int, input().split()))
ans = 0
s = -1
k = 0
for i in range(n - 1):
	if a[i + 1] - a[i] == 1:
		if s == -1:
			s = i
	elif s != -1:
		k = i - s - 1
		if a[s] == 1:
			k += 1
		s = -1
		ans = max(ans, k)
if s != -1:
	k = i - s
	if a[s] == 1 or a[n - 1] == 1000:
		k += 1
	ans = max(ans, k)
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = 0
count = 1
a = [0] + a + [1001]
for i in range(1, n + 2):
	if a[i] - a[i - 1] == 1:
		count += 1
	else:
		m = max(m, count - 2)
		count = 1
m = max(m, count - 2)
print(m)


def main():
	buf = input()
	n = int(buf)
	buf = input()
	buflist = buf.split()
	a = list(map(int, buflist))
	a.insert(0, 0)
	a.append(1001)
	count = -1
	max_count = 0
	last_number = None
	for (i, number) in enumerate(a):
		if last_number == None:
			pass
		elif number == last_number + 1:
			count += 1
			if count > max_count:
				max_count = count
		else:
			count = -1
		last_number = number
	print(max_count)
main()


I = lambda : int(input())
ID = lambda : map(int, input().split())
IL = lambda : list(ID())
n = I()
a = IL()
cnt = 0
maxi = 0
for i in range(n - 1):
	if a[i + 1] - a[i] == 1:
		cnt += 1
		if a[i] == 1 or a[i + 1] == 1000:
			cnt += 1
	else:
		maxi = max(maxi, cnt)
		cnt = 0
maxi = max(maxi, cnt)
print(max(maxi - 1, 0))


N = int(input())
A = [int(c) for c in input().join(['0 ', ' 1001']).split()]
r = [i for i in range(1, N + 1) if A[i + 1] - A[i - 1] == 2]
m = len(r)
if m < 2:
	ans = m
else:
	(ans, cnt) = (0, 1)
	for i in range(1, m):
		cnt = cnt + 1 if r[i] - r[i - 1] == 1 else 1
		ans = max(ans, cnt)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
fin = 0
ans = 0
arr = [0] + arr + [1001]
last = -2
for i in range(n + 2):
	if last == arr[i] - 1:
		last = arr[i]
		ans += 1
		if ans > fin:
			fin = ans
	else:
		last = arr[i]
		ans = 0
if fin == 0:
	fin += 1
print(fin - 1)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
n = int(input())
l = list(map(int, input().split()))
maxi = 0
if n == 1000:
	print(1000)
	exit()
for i in range(n):
	for j in range(i, n):
		if i - 1 >= 0 and j + 1 < n:
			if l[j + 1] - l[i - 1] - 1 == j - i + 1:
				maxi = max(j - i + 1, maxi)
		if i - 1 < 0 and j + 1 < n:
			if l[j + 1] - 1 == j - i + 1:
				maxi = max(j - i + 1, maxi)
		if i - 1 >= 0 and j + 1 >= n:
			z = j - 1
			if 1000 - l[i - 1] - 1 == z - i + 1:
				maxi = max(j - i + 1, maxi)
print(maxi)


n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
patch = []
c = 0
st = 0
maxi = 0
for i in range(n - 1):
	if l[i] == l[i + 1] - 1:
		c += 1
	else:
		if l[st] == 1:
			maxi = max(maxi, c)
		else:
			maxi = max(maxi, c - 1)
		c = 0
		st = i + 1
if c != 0:
	if l[st] == 1:
		maxi = max(maxi, c)
	elif l[-1] == 1000:
		maxi = max(maxi, c)
	else:
		maxi = max(maxi, c - 1)
print(maxi)


n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [1001]
ans = 0
for i in range(len(a)):
	for j in range(i + 3, len(a) + 1):
		if a[i:j] == list(range(a[i], a[i] + j - i)):
			ans = max(ans, j - i - 2)
print(ans)


n = int(input())
s = list(map(int, input().split()))
s = [0] + s[:] + [1001]
c = 0
maxc = 0
for i in range(1, len(s)):
	if s[i] - s[i - 1] == 1:
		c += 1
		if c > maxc:
			maxc = c - 1
	else:
		c = 0
print(maxc)


import sys
n = int(input())
a = [int(x) for x in input().split()]
if n == 1:
	print(0)
	sys.exit()
b = [a[0]]
for i in range(1, n):
	b.append(a[i] - a[i - 1])
b = b[1:]
c = []
curr = int(b[0] == 1)
for i in range(1, len(b)):
	if b[i] == 1:
		curr += 1
	if b[i] != 1 and b[i - 1] == 1:
		c.append(curr - 1)
		curr = 0
if b[-1] == 1:
	c.append(curr - 1)
if a[0] == 1 and a[1] == 2:
	c[0] += 1
if a[-1] == 1000 and a[-2] == 999:
	c[-1] += 1
try:
	print(max(c))
except:
	print(0)


import sys
x = int(input())
a = list(map(int, input().split(' ')))
ct = 0
if x == 1:
	print(0)
	sys.exit(0)
run = False
runct = 0
for i in range(x):
	if a[i] == 1 and a[i + 1] == 2 or (a[i] == 1000 and a[i - 1] == 999):
		run = True
		runct += 1
	elif i > 0 and i < x - 1 and (a[i] == a[i - 1] + 1) and (a[i] + 1 == a[i + 1]):
		run = True
		runct += 1
	else:
		run = False
		ct = max(ct, runct)
		runct = 0
ct = max(ct, runct)
print(ct)


n = int(input())
s = list(map(int, input().split()))
mx = 0
x = 0
for i in range(1, n):
	if s[i] - s[i - 1] == 1:
		x += 1
	else:
		x = 0
	mx = max(mx, x)
if s[mx] - 1 == mx or s[-mx - 1] == 1000 - mx:
	print(mx)
else:
	print(max(0, mx - 1))


def solve(numbers):
	max_can_erase = 0
	current_start = None
	previous = None
	for value in numbers:
		if previous is None:
			previous = value
			current_start = value
			continue
		elif value == previous + 1:
			pass
		else:
			can_erase = previous - current_start
			if current_start > 1:
				can_erase -= 1
			max_can_erase = max(max_can_erase, can_erase)
			current_start = value
		previous = value
	can_erase = numbers[-1] - current_start
	if current_start > 1 and numbers[-1] < 1000:
		can_erase -= 1
	max_can_erase = max(max_can_erase, can_erase)
	return max_can_erase
n = int(input())
xs = list(map(int, input().split()))[:n]
print(solve(xs))


n = int(input())
nums = list(map(int, input().strip().split()))
nums = [0] + nums + [1001]
l = 0
c = 0
counted = False
for i in range(n + 1):
	if nums[i] + 1 == nums[i + 1]:
		c += 1
		if not counted:
			counted = True
	elif counted:
		if l < c - 1:
			l = c - 1
		c = 0
		counted = False
if counted:
	if l < c - 1:
		l = c - 1
	c = 0
	counted = False
print(l)


x = int(input())
listik = list(map(int, input().split()))
(counter, counterik) = (0, 0)
i = 0
if x == 1000:
	print(1000)
elif listik[0] == 1 and listik[-1] == x:
	print(x - 1)
else:
	if listik[0] == 1 and listik[1] == 2:
		counterik += 1
	while i < x - 1:
		if listik[i] + 1 == listik[i + 1]:
			counterik += 1
		elif counterik != 0:
			counter = max(counter, counterik - 1)
			counterik = 0
		i += 1
	if counterik != 0:
		if listik[-1] == 1000 and listik[-2] == 999:
			counter = max(counter, counterik)
		else:
			counter = max(counter, counterik - 1)
	print(counter)


size = int(input())
arr = list(map(int, input().split()))
count = m = 0
for i in range(size - 1):
	if arr[i] + 1 == arr[i + 1]:
		if i == 0 and arr[i] == 1 or (i == size - 2 and arr[i + 1] == 1000):
			count += 1
		count += 1
	else:
		count = 0
	if m < count:
		m = count
if m == 0:
	print(0)
else:
	print(m - 1)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
lis = [1 for i in range(n)]
i = 0
last = -1
while i < n:
	if a[i] == last + 1:
		last += 1
		lis[i] = lis[i - 1] + 1
	else:
		last = a[i]
	i += 1
maximum = 0
for i in range(n):
	ans = lis[i]
	if a[0] == 1 and lis[i] - i == 1:
		ans -= 1
	elif a[i] != 1000:
		ans -= 2
	else:
		ans -= 1
	maximum = max(maximum, ans)
print(maximum)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
za = getIntList()
za = [0] + za + [1001]
N += 2
re = 0
ac = 0
for i in range(1, N):
	if za[i] == za[i - 1] + 1:
		ac += 1
		re = max(re, ac - 1)
	else:
		ac = 0
print(re)


d = int(input())
g = [int(i) for i in input().split()]
count = 0
op = []
i = 0
j = 0
if g[0] == 1:
	for i in range(len(g) - 1):
		if g[i] + 1 == g[i + 1]:
			count += 1
		else:
			op.append(count)
			break
	op.append(count)
	count = 0
for j in range(i, len(g) - 1):
	if g[j] + 1 == g[j + 1]:
		count += 1
	else:
		if g[j] - 1000 == -1:
			op.append(count)
		else:
			op.append(count - 1)
		count = 0
if count != 0:
	if 1000 - g[j] == 1:
		op.append(count)
	else:
		op.append(count - 1)
else:
	op.append(count)
print(max(op))


n = int(input())
a = list(map(int, input().split()))
x = []
c = 1
if a[0] == 1:
	c += 1
for i in range(n - 1):
	if a[i + 1] - a[i] is 1:
		c += 1
	else:
		x.append(c)
		c = 1
if a[n - 1] == 1000:
	c += 1
x.append(c)
q = max(x)
if q > 2:
	print(q - 2)
else:
	print(0)


n = int(input())
arr = [int(x) for x in input().split()]
final = [0] + arr + [1001]
c = 0
ans = 0
for x in range(1, n + 1):
	if final[x + 1] - final[x - 1] == 2:
		c += 1
	else:
		ans = max(ans, c)
		c = 0
print(max(c, ans))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
curr = 0
m = 1
for i in range(1, n):
	if a[i] - a[i - 1] == 1:
		curr = curr + 1
	else:
		m = max(m, curr)
		curr = 0
	if i == 1 and curr > 0 and (a[0] == 1):
		curr = curr + 1
	if i == n - 1 and curr > 0 and (a[n - 1] == 1000):
		curr = curr + 1
if curr > 1:
	m = max(m, curr)
m = m - 1
if m == n:
	m = m - 1
print(m)


input()
a = [x - i for (i, x) in enumerate([0] + [*map(int, input().split())] + [1001])]
print(max(1, 1, *map(len, ''.join((' *'[x == y] for (x, y) in zip(a, a[1:]))).split())) - 1)


n = int(input())
l = [0] + list(map(int, input().split()))
l.append(1001)
(m, c) = (1, 0)
for i in range(1, n + 2):
	if l[i] - l[i - 1] == 1:
		c += 1
	else:
		m = max(m, c)
		c = 0
m = max(m, c)
print(m - 1)


n = int(input())
m = [int(i) for i in input().split()]
rs = 0
for i in range(n):
	for j in range(i):
		if m[i] - m[j] == i - j:
			if m[j] == 1 or m[i] == 1000:
				rs = max(rs, i - j)
			else:
				rs = max(rs, i - j - 1)
print(rs)


n = int(input())
ai = [0] + list(map(int, input().split())) + [1001]
ans = 0
num = 1
for i in range(1, n + 2):
	if ai[i] == ai[i - 1] + 1:
		num += 1
	else:
		ans = max(ans, num - 2)
		num = 1
print(max(ans, num - 2))


n = int(input())
n += 2
a = list(map(int, input().split()))
a = [0] + a
a = a + [1001]
i = 0
ans = 0
while i != n:
	t = 0
	while i + 1 != n and a[i] + 1 == a[i + 1]:
		i += 1
		t += 1
	i += 1
	ans = max(ans, t - 1)
print(ans)


n = int(input())
nums = [int(x) for x in input().split(' ')]

def num_can_erase(n, nums):
	nums.insert(0, 0)
	nums.append(1001)
	longest = 0
	curr = 1
	for i in range(len(nums) - 1):
		if nums[i] + 1 == nums[i + 1]:
			curr += 1
			if curr > longest:
				longest = curr
		else:
			curr = 1
	return max(0, longest - 2)
print(num_can_erase(n, nums))


x = int(input())
a = list(map(int, input().split()))
c = 0
e = 0
for i in range(0, x - 1):
	if abs(a[i] - a[i + 1]) == 1:
		c += 1
		if a[i] == 1:
			c += 1
		if a[i + 1] == 1000:
			c += 1
	else:
		if c > e:
			e = c
		c = 0
if c > e:
	e = c
if x == 1 or e == 0:
	print('0\n')
elif e == x - 1:
	if a[0] == 1:
		print(e - 1)
	elif a[x - 1] == 1000:
		print(e)
	else:
		print(e - 1)
elif e >= x:
	print(e - 1)
else:
	print(e - 1)
print('\n')


n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(0)
	exit(0)
elif n == 2:
	if arr[1] == 2 or arr[-2] == 999:
		print(1)
		exit(0)
	else:
		print(0)
		exit(0)
idx = ans = 0
while idx + 1 < n:
	cnt = 0
	if arr[idx] == 1 and arr[idx + 1] == 2:
		cnt = 1
	while idx + 2 < n and arr[idx] + 1 == arr[idx + 1] == arr[idx + 2] - 1:
		idx += 1
		cnt += 1
	if idx < n - 1 and arr[idx] == 999 and (arr[idx + 1] == 1000):
		cnt += 1
	idx += 1
	ans = max(ans, cnt)
print(ans)


count = int(input())
array = [int(x) for x in input().split(' ')]
max_diff = 0
(max_start, max_length) = (0, 1)
(start, length) = (0, 1)
value = 0
value2 = 0
for i in range(count - 1):
	curr = array[i]
	next = array[i + 1]
	if next == curr + 1:
		length += 1
	else:
		if array[start + length - 1] == 1000 or array[start] == 1:
			value2 = length - 1
		else:
			value2 = length - 2
		value = max(value, value2)
		length = 1
		start = i + 1
if length > max_length:
	max_length = length
if array[start + length - 1] == 1000 or array[start] == 1:
	value2 = length - 1
else:
	value2 = length - 2
print(max(value, value2))


n = int(input())
l = list(map(int, input().split()))
t = []
count = 1
for i in range(1, n):
	if l[i] == l[i - 1] + 1:
		count += 1
	else:
		t.append(count)
		count = 1
t.append(count)
if t.index(max(t)) == 0 and l[0] == 1 or (t[-1] == max(t) and l[-1] == 1000):
	print(max(t) - 1)
elif max(t) <= 2:
	print(0)
else:
	print(max(t) - 2)


n = int(input())
array = list(map(int, list(input().split(' '))))
a = [0] * 1000
for i in range(1, n + 1):
	a[i] = array[i - 1]
n += 1
a[n] = 1001
ans = 0
for i in range(n + 1):
	for j in range(i + 1, n + 1):
		if a[j] - a[i] == j - i:
			ans = max(ans, j - i - 1)
print(ans)


a = int(input())
(c, s) = (0, 0)
z = [0] + list(map(int, input().split())) + [1001]
for i in range(1, a + 2):
	if z[i] - z[i - 1] == 1:
		c += 1
	else:
		c = 0
	s = max(s, c - 1)
print(s)


def fun(m):
	if l[m[0]] == 1 or l[m[len(m) - 1]] == 1000:
		return len(m) - 1
	else:
		return len(m) - 2
n = int(input())
l = list(map(int, input().split()))
if len(l) == 1:
	print('0')
else:
	m = []
	z = [0]
	j = 0
	for i in range(1, n):
		if l[i] - l[i - 1] == 1:
			j = j + 1
			if i - 1 not in m:
				m.append(i - 1)
			if i not in m:
				m.append(i)
		elif j != 0:
			x = fun(m)
			z.append(x)
			m = []
			j = 0
	if len(m) != 0:
		x = fun(m)
		z.append(x)
	print(max(z))


def mainA():
	n = int(input())
	a = [0] + [int(e) for e in input().split()] + [1001]
	(ans, mx) = (0, 0)
	for i in range(1, n + 1):
		if a[i] == a[i - 1] + 1 and a[i] == a[i + 1] - 1:
			ans += 1
			mx = max(mx, ans)
		else:
			ans = 0
	print(mx)
mainA()


n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n):
	for j in range(i + 2, n):
		if arr[j] - arr[i] == j - i:
			ans = max(ans, j - i - 1)
for i in range(n):
	if arr[i] == i + 1:
		ans = max(ans, i)
for i in range(n):
	if n - i - 1 == 1000 - arr[i]:
		ans = max(ans, n - i - 1)
print(ans)


def inint():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def main():
	n = inint()
	a = inlist()
	a = [0] + a + [1001]
	ans = 0
	i = 0
	while i <= n:
		j = i + 1
		while j <= n + 1 and a[j] == a[j - 1] + 1:
			j += 1
		ans = max(ans, j - i - 2)
		i = j
	print(ans)
main()


n = int(input())
l = list(map(int, input().split()))
ans = 0
cur = l[0]
curIdx = 0
for x in range(1, n):
	if x - curIdx == l[x] - cur:
		ans = max(ans, x - curIdx - 1 + (1 if cur == 1 else 0) + (1 if l[x] == 1000 else 0))
	else:
		cur = l[x]
		curIdx = x
print(ans)


n = int(input())
a = input()
a = list(map(int, a.split(' ')))
x = []
m = -1
if n == 1:
	print(0)
else:
	for i in range(0, n - 1):
		if a[i] == a[i + 1] - 1:
			m += 1
		else:
			x.append(m)
			m = -1
	if m > -1:
		x.append(m)
	if a[0] == 1:
		x[0] = x[0] + 1
	if a[n - 1] == 1000 and a[n - 2] == 999:
		x[-1] += 1
	m = x[0]
	for i in range(1, len(x)):
		if m < x[i]:
			m = x[i]
	if m == -1:
		print(0)
	else:
		print(m)


t = int(input())
list_ = [int(i) for i in input().split()]
con = []
running = 0
max_ = 0
for x in range(t):
	if x != t - 1 and list_[x + 1] - list_[x] == 1:
		con.append(list_[x])
		running = 1
	elif running == 1 and x != t - 1 and (list_[x + 1] - list_[x] != 1):
		con.append(list_[x])
		running = 0
	elif running == 1 and x == t - 1:
		con.append(list_[x])
		running = 0
	if len(con) > 0:
		if con[0] == 1 or con[-1] == 1000:
			ans = len(con) - 1
		else:
			ans = len(con) - 2
		if ans > max_:
			max_ = ans
	if running == 0:
		con = []
print(max_)


n = int(input())
arr = [0] + list(map(int, input().strip().split())) + [1001]
c = 0
m = 0
for i in range(n + 1):
	if arr[i + 1] - arr[i] == 1:
		c += 1
	else:
		c = 0
	m = max(m, c - 1)
print(m)


km = 0
k = 0
n = int(input())
a = input().split()
if n == 1:
	print(0)
else:
	for i in range(n):
		a[i] = int(a[i])
	for i in range(n):
		if i == n - 1 and a[i] == 1000 and (a[i - 1] == 999):
			k += 1
		elif i == 0 and a[i] == 1 and (a[i + 1] == 2):
			k += 1
		elif 0 != i != n - 1 and a[i + 1] == a[i] + 1 and (a[i - 1] == a[i] - 1):
			k += 1
		else:
			if k > km:
				km = k
			k = 0
	if k > km:
		km = k
		k = 0
	print(km)


input()
a = [0] + [int(x) for x in input().split()] + [1001]
i = 1001
l = [0, -2]
while a != []:
	x = a.pop()
	if x != i:
		l.append(-1)
		i = x - 1
	else:
		l[-1] += 1
		i -= 1
print(max(l))


N = int(input())
L = list(map(int, input().split(' ')))
last = L[0]
S = 0
tmp = 0
ok = 0
for i in range(1, len(L)):
	if last + 1 == L[i]:
		tmp += 1
		if last == 1 or L[i] == 1000:
			tmp += 1
		ok = 1
	elif ok:
		if tmp - 1 > S:
			S = tmp - 1
		tmp = 0
		ok = 0
	last = L[i]
if ok:
	if tmp - 1 > S:
		S = tmp - 1
print(S)


n = int(input())
a = [int(s) for s in input().split()]
max = -10 ** 10
for i in range(len(a) - 1):
	posl = 1
	k = 1000
	while i + 1 < len(a) and a[i] + 1 == a[i + 1]:
		if k == 1000:
			k = i
		posl += 1
		i += 1
	if k != 1000 and a[k] == 1:
		posl += 1
	if a[i] == 1000:
		posl += 1
	posl -= 2
	if posl > max:
		max = posl
if max == -1 or max == -10 ** 10:
	print(0)
else:
	print(max)


n = int(input())
lst = [int(i) for i in input().split()]
a = [0] + lst + [1001]
(result, count) = (1, 1)
for j in range(1, len(a)):
	if a[j - 1] + 1 == a[j]:
		count += 1
		if result < count:
			result = count
	else:
		count = 1
if result < count:
	result = count
if result == 1:
	result += 1
print(result - 2)


import sys
import math
sys.setrecursionlimit(100000000)
lines = []
for line in sys.stdin:
	lines.append(line.rstrip('\n'))
N = int(lines.pop(0))
numbers = [int(x) for x in lines.pop(0).split(' ')]
numbers = [0] + numbers + [1001]
N = len(numbers)

def doTheReduction(numbers):
	previous = -1
	cumul = 0
	cumuls = []
	for i in range(0, N):
		if numbers[i] == previous + 1:
			cumul += 1
		if numbers[i] != previous + 1 or i == N - 1:
			cumuls.append(cumul)
			cumul = 1
		previous = numbers[i]
	return cumuls
reduction = doTheReduction(numbers)
print(max(0, max(reduction) - 2))


n = int(input())
a = map(int, input().split())
max_err = 0
curr_err = 1
last_a = -500
for ai in a:
	if ai == last_a + 1:
		curr_err += 1
		curr_err += 1 if last_a == 1 else 0
		curr_err += 1 if ai == 1000 else 0
	else:
		max_err = max([max_err, curr_err])
		curr_err = 1
	last_a = ai
max_err = max([max_err, curr_err])
print(max([max_err - 2, 0]))


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def msi():
	return map(str, input().strip().split(' '))

def lsi():
	return list(msi())
n = ii()
a = li()
b = [0]
b = b + a
b.append(1001)
x = 0
for i in range(n + 2):
	c = 0
	for j in range(i + 1, n + 2):
		if b[j] - j == b[i] - i:
			c += 1
	x = max(x, c - 1)
print(x)


n = int(input())
arr = list(map(int, input().split()))
arr.insert(0, 0)
arr.insert(len(arr), 1001)
n += 2
res = 0
i = 0
while i < n - 1:
	if arr[i] == arr[i + 1] - 1:
		j = i + 1
		while j < n - 1 and arr[j] == arr[j + 1] - 1:
			j += 1
		seq = j - i - 1
		res = max(res, seq)
		i = j
	i += 1
print(res)


import sys
input = sys.stdin.readline
for _ in range(1):
	n = int(input())
	o = list(map(int, input().split()))
	l = [0] + o + [1001]
	ans = 0
	for i in range(len(l)):
		for j in range(i + 1, len(l)):
			if l[i] - i == l[j] - j:
				ans = max(j - i - 1, ans)
	print(ans)


n = int(input())
l = list(map(int, input().split()))
maxval = 0
count = 0
last = 0
for i in range(1, n):
	if l[i] == l[i - 1] + 1:
		count += 1
	else:
		count = 0
		last = i
	if l[last] == 1 or l[i] == 1000:
		maxval = max(count, maxval)
	else:
		maxval = max(count - 1, maxval)
print(maxval)


def user99():
	n = int(input())
	a = list(map(int, input().split()))
	b = [[] for i in range(n)]
	ptr = 0
	for i in range(n):
		if i >= 1 and a[i - 1] + 1 != a[i]:
			ptr += 1
		b[ptr].append(a[i])
	ans = 0
	for i in b:
		if len(i) == 0:
			continue
		x = len(i) - 2
		if i[0] == 1:
			x += 1
		if i[-1] == 10 ** 3:
			x += 1
		ans = max(ans, x)
	print(ans)
user99()


n = int(input())
arr = [0] + list(map(int, input().split()))
arr.append(1001)
max_ = 0
kek = 0
for i in range(1, len(arr)):
	if arr[i] - 1 == arr[i - 1]:
		kek += 1
	else:
		max_ = max(max_, kek - 1)
		kek = 0
max_ = max(max_, kek - 1)
print(max_)


n = int(input())
l = [int(x) for x in input().split()]
l.append(1003)
sum = 0
dem = 0
dau = 0
cuoi = n
_dau = 0
_cuoi = 0
if n == 1:
	print(0)
else:
	if l[0] == 1:
		for i in range(n):
			if l[i + 1] == l[i] + 1:
				dem += 1
			else:
				_dau += dem
				dau = i + 1
				break
	if dem == 999 or dau == n:
		print(dem)
	else:
		dem = 0
		if l[-2] == 1000:
			for i in range(n - 1, dau - 1, -1):
				if l[i] == l[i - 1] + 1:
					dem += 1
				else:
					_cuoi += dem
					cuoi = i
					break
			if i == 1:
				cuoi = 1
		if dem == 999 or cuoi == 1:
			print(dem)
		else:
			dem = 0
			maxx = 0
			a = l[dau:cuoi]
			a.append(1003)
			for i in range(len(a) - 1):
				if a[i + 1] == a[i] + 1:
					dem += 1
				else:
					if dem != 0:
						sum = dem - 1
						if sum > maxx:
							maxx = sum
					dem = 0
			print(max(maxx, _dau, _cuoi))


n = int(input())
A = list(map(int, input().split()))
res = 0
if A[0] == 1:
	cnt = 2
else:
	cnt = 1
for i in range(n - 1):
	if A[i] + 1 == A[i + 1]:
		cnt += 1
		if A[i + 1] == 1000:
			cnt += 1
	else:
		res = max(cnt, res)
		cnt = 1
else:
	res = max(cnt, res)
ans = max(res - 2, 0)
print(ans)


def main():
	n = int(input())
	arr = input().split(' ')
	for j in range(n):
		arr[j] = int(arr[j])
	prev = arr[0]
	ct = 0
	m = 0
	if n == 1:
		print(0)
		return None
	if arr[0] == 1 and arr[1] == 2:
		ct = 1
		m = 1
	for j in range(1, n - 1):
		if arr[j] == prev + 1 and arr[j] == arr[j + 1] - 1:
			ct = ct + 1
			m = max(ct, m)
		else:
			ct = 0
		prev = arr[j]
	if arr[n - 1] == arr[n - 2] + 1 and arr[n - 1] == 1000:
		ct = ct + 1
		m = max(m, ct)
	print(m)
main()


n = int(input())
arr = list(map(int, input().split()))
eraseable = 0
if n == 1:
	print(0)
	exit(0)
consecutive = False
if arr[0] == 1 and arr[1] == 2:
	consecutive = 1
for i in range(1, n - 1):
	if arr[i] - arr[i - 1] == 1 and arr[i + 1] - arr[i] == 1:
		consecutive += 1
	else:
		eraseable = max(consecutive, eraseable)
		consecutive = 0
if arr[-1] == 1000 and arr[-2] == 999:
	consecutive += 1
	eraseable = max(consecutive, eraseable)
elif consecutive > 0:
	eraseable = max(consecutive, eraseable)
print(eraseable)


n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	cur_len = 0
	max_len = 0
	if arr[0] == 1 and arr[1] == 2:
		cur_len = 1
	for i in range(1, n - 1):
		if arr[i] - arr[i - 1] == 1 and arr[i + 1] - arr[i] == 1:
			cur_len += 1
		else:
			if cur_len > max_len:
				max_len = cur_len
			cur_len = 0
	if arr[-1] == 1000 and arr[-2] == 999:
		cur_len += 1
	if cur_len > max_len:
		max_len = cur_len
	print(max_len)


import os
import sys
import math
import collections
import cmath

def mp():
	return map(int, input().split())

def inp():
	return input()
n = int(inp())
arr = list(mp())
d = []
count = 1
i = 0
j = 1
if n == 1:
	print(0)
	exit()
while True:
	for j in range(i + 1, n):
		if arr[j] == arr[i] + j - i and (arr[i] == 1 and arr[j] != 1000):
			count += 1
			d.append(count - 1)
		elif arr[j] == arr[i] + j - i and (arr[i] != 1 and arr[j] == 1000):
			count += 1
			d.append(count - 1)
		elif arr[j] == arr[i] + j - i and (arr[i] == 1 and arr[j] == 1000):
			count += 1
			d.append(count)
		elif arr[j] == arr[i] + j - i and (arr[i] != 1 and arr[j] != 1000):
			count += 1
			d.append(count - 2)
		elif arr[j] != arr[i] + j - i:
			count = 1
			d.append(count - 1)
			i = j
			break
		if j == n - 1:
			i = n - 1
			break
	if i == n - 1:
		break
print(max(d))


n = int(input())
l = [0]
inp = [int(x) for x in input().split()]
for i in range(n):
	l.append(inp[i])
l.append(1001)
ans = 0
cur = 0
for i in range(1, len(l) - 1):
	if l[i - 1] + 1 == l[i] and l[i + 1] == l[i] + 1:
		cur += 1
	else:
		cur = 0
	ans = max(ans, cur)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.append(l[-1] + 1)
c = 0
d = []
if n > 1:
	for i in range(1, n):
		if l[i] - l[i - 1] == 1:
			if l[i - 1] == 1:
				c += 1
			elif l[i] == 1000:
				c += 1
			c += 1
		else:
			d.append(c - 1)
			c = 0
	if c <= 0:
		c = 1
	d.append(c - 1)
	print(max(d))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
count = ans = 0
if n >= 2 and a[0] == 1 and (a[1] == 2):
	count += 1
for i in range(1, n - 1):
	if a[i - 1] + 1 == a[i] and a[i + 1] - 1 == a[i]:
		count += 1
	else:
		ans = max(ans, count)
		count = 0
if n >= 2 and a[-1] == 1000 and (a[-2] == 999):
	count += 1
ans = max(count, ans)
print(ans)


n = int(input())
a = [0] + [int(i) for i in input().split()] + [1001]
ans = 0
for j in range(1, n + 1):
	i = j
	f = 0
	while i < n + 1 and a[i] == a[i - 1] + 1 and (a[i] == a[i + 1] - 1):
		f += 1
		i += 1
	ans = max(ans, f)
print(ans)


n = int(input())
A = [int(num) for num in input().split(' ')]
current_seq = []
current_seq_start = 0
best_result = 0
for (i, a) in enumerate(A):
	if i == 0:
		current_seq.append(a)
	elif a == current_seq[-1] + 1:
		current_seq.append(a)
	else:
		current_result = len(current_seq) - 2
		if current_seq_start == 0 and current_seq[0] == 1:
			current_result += 1
		if current_result > best_result:
			best_result = current_result
		current_seq_start = i
		current_seq = [a]
current_result = len(current_seq) - 2
if current_seq[-1] == 1000:
	current_result += 1
if current_seq_start == 0 and current_seq[0] == 1:
	current_result += 1
if current_result > best_result:
	best_result = current_result
print(best_result)


import bisect
import re
n = eval(input())
a = list(map(int, input().split()))
ans = 0
k = 0
a.insert(0, 0)
a.append(1001)
for i in range(1, len(a)):
	if a[i] - a[i - 1] == 1:
		k += 1
	else:
		ans = max(ans, k)
		k = 0
ans = max(ans, k)
print(max(0, ans - 1))


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
c = 0
ma = 0
for i in range(0, n + 1):
	if a[i + 1] - a[i] == 1:
		c += 1
	else:
		c = 0
	ma = max(ma, c - 1)
print(ma)


n = int(input())
arr = [0] + [int(x) for x in input().split()] + [1001]
arr2 = []
for (a, b) in zip(arr, arr[1:]):
	arr2.append(b - a)
longest = 0
current = 0
for x in arr2:
	if x == 1:
		current += 1
	else:
		longest = max(longest, current)
		current = 0
longest = max(longest, current)
print(max(longest - 1, 0))


n = int(input())
n += 2
a = list(map(int, input().split()))
a = [0] + a
a = a + [1001]
ind = 0
ans = 0
while ind != n:
	now = 0
	while ind + 1 != n and a[ind] + 1 == a[ind + 1]:
		ind += 1
		now += 1
	ind += 1
	ans = max(ans, now - 1)
print(ans)


import sys, math
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
temp = []
i = 0
ans = 0
while i < n:
	now = arr[i]
	size = 1
	j = i + 1
	while j < n:
		if arr[j] == now + 1:
			size += 1
			now = arr[j]
		else:
			break
		j += 1
	if size > 1:
		temp.append((i, j - 1))
	i = j
for i in temp:
	if i[0] == 0 and i[1] == n - 1:
		if arr[i[0]] == 1 or arr[i[1]] == 1000:
			ans = max(ans, i[1] - i[0])
		else:
			ans = max(ans, i[1] - i[0] - 1)
	elif i[0] == 0:
		if arr[i[0]] == 1:
			ans = max(ans, i[1] - i[0])
		else:
			ans = max(ans, i[1] - i[0] - 1)
	elif i[1] == n - 1:
		if arr[i[1]] == 1000:
			ans = max(ans, i[1] - i[0])
		else:
			ans = max(ans, i[1] - i[0] - 1)
	else:
		ans = max(ans, i[1] - i[0] - 1)
print(ans)


def main():
	n = int(input())
	a = [int(c) for c in input().join(['0 ', ' 1001']).split()]
	rpos = [i for i in range(1, n + 1) if a[i + 1] - a[i - 1] == 2]
	if len(rpos) < 2:
		ans = len(rpos)
	else:
		(ans, cnt) = (0, 1)
		for i in range(1, len(rpos)):
			cnt = cnt + 1 if rpos[i] - rpos[i - 1] == 1 else 1
			ans = max(ans, cnt)
	print(ans)
main()


n = int(input())
a = [int(s) for s in input().split()]
check = [False] * n
ans = 0
for i in range(1, n - 1):
	if a[i] == a[i - 1] + 1 == a[i + 1] - 1:
		check[i] = True
if n > 1:
	if a[0] == a[1] - 1 == 1:
		check[0] = True
	if a[-1] == a[-2] + 1 == 1000:
		check[n - 1] = True
ans = 0
curr = 0
for i in range(n):
	if check[i]:
		curr += 1
		if curr > ans:
			ans = curr
	else:
		curr = 0
print(ans)


n = int(input())
a = list(map(int, input().split()))
ct = 0
flag = 0
m = 0
for i in range(n - 1):
	if a[i] == a[i + 1] - 1:
		if a[i] == 1:
			ct += 1
		if a[i + 1] == 1000:
			ct += 1
		ct += 1
		m = max(ct - 1, m)
	else:
		ct = 0
print(m)


n = int(input())
A = list(map(int, input().split()))
A = [0] + A + [1001]
ANS = 0
count = 0
for i in range(1, n + 1):
	if A[i] == A[i - 1] + 1 and A[i] == A[i + 1] - 1:
		count += 1
	else:
		ANS = max(ANS, count)
		count = 0
ANS = max(ANS, count)
print(ANS)


def main():
	n = int(input())
	arr = [int(x) for x in input().strip().split()]
	arr = [0] + arr + [1001]
	n = n + 2
	i = 0
	ans = 0
	while i < n:
		j = i
		while j < n and arr[j] - arr[i] == j - i:
			j += 1
		ans = max(ans, j - i - 2)
		i = j
	print(ans)
	return
main()


n = int(input())
l = list(map(int, input().split()))
ma = 0
s = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if l[j] - l[i] == j - i:
			s = j - i - 1
			if l[i] == 1:
				s = s + 1
			if l[j] == 1000:
				s = s + 1
			ma = max(ma, s)
print(ma)


n = int(input()) + 2
l = [0] + list(map(int, input().split())) + [1001]
M = 0
i = 0
while i < n - 1:
	s = 1
	j = i + 1
	while j < n:
		if l[j] == l[j - 1] + 1:
			s += 1
			j += 1
		else:
			break
	if s > M:
		M = s
	i = j
print(M - 2) if M - 2 > 0 else print(0)


a = int(input())
b = list(map(int, input().split()))
b.insert(0, 0)
b = b + [1001]
mx = 0
for i in range(0, a + 1):
	for j in range(i + 1, a + 2):
		if b[j] - b[i] == j - i and mx < j - i - 1:
			mx = j - i - 1
print(mx)


input()
p = m = c = 0
for x in [*map(int, input().split()), 1001]:
	c = (0, c + 1)[p + 1 == x]
	m = max(m, c - 1)
	p = x
print(m)


import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
maxx = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if j - i == l[j] - l[i]:
			if l[i] == 1 or l[j] == 1000:
				maxx = max(maxx, j - i)
			else:
				maxx = max(maxx, j - i - 1)
print(maxx)


def main():
	n = int(input())
	a = [0] + list(map(int, input().split())) + [1001]
	if n == 1:
		return print(0)
	answer = 0
	c = 0
	for i in range(n + 1):
		if a[i + 1] - a[i] == 1:
			c += 1
		else:
			c = 0
		answer = max(answer, c - 1)
	return print(answer)
main()


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if test:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = False
test = False

def main():
	d = get_int()
	li = get_list()
	if d == 1000:
		print(1000)
		return
	res = 0
	c_streak = 0
	for (i, ele) in enumerate(li):
		if i == len(li) - 1:
			break
		if ele + 1 == li[i + 1]:
			if i == 0 and ele == 1 or (i == len(li) - 2 and li[-1] == 1000):
				c_streak += 1
			c_streak += 1
		else:
			res = max(c_streak - 1, res) if c_streak > 0 else res
			c_streak = 0
	res = max(c_streak - 1, res) if c_streak > 0 else res
	print(res)
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if test else main()
else:
	cProfile.run('main()') if test else main()


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
q = 0
for i in range(n + 2):
	for j in range(i + 1, n + 2):
		if a[j] - a[i] - 1 > q and a[j] - a[i] - 1 == j - i - 1:
			q = a[j] - a[i] - 1
print(q)


num = int(input())
arr = list(map(int, input().split())) + [10000]
sub_arr = []
mx = 0
ans_arr = []
for i in range(num):
	if arr[i + 1] - arr[i] == 1:
		sub_arr.append(arr[i])
	else:
		if sub_arr:
			sub_arr.append(arr[i])
		if len(sub_arr) > mx:
			mx = len(sub_arr)
			ans_arr = sub_arr[:]
		if len(sub_arr) == mx > 1 and (sub_arr[0] == 1 or sub_arr[-1] == 1000):
			ans_arr = sub_arr[:]
		sub_arr = []
if not ans_arr:
	print(0)
elif ans_arr[0] == 1 or ans_arr[-1] == 1000:
	print(max(0, mx - 1))
else:
	print(max(0, mx - 2))


n = int(input())
arr = [int(x) for x in input().split()]
ma = 0
cnt = 0
if len(arr) == 1000:
	print(1000)
else:
	for i in range(len(arr) - 1):
		if arr[i + 1] == arr[i] + 1:
			cnt += 1
			if arr[i] == 1 or arr[i + 1] == 1000:
				cnt += 1
		else:
			ma = max(ma, cnt)
			cnt = 0
ma = max(ma, cnt)
print(max(0, ma - 1))


n = int(input())
li = list(map(int, input().split()))
cnt = 0
a = []
for i in range(n - 1):
	if li[i] == li[i + 1] - 1:
		if li[i] == 1:
			cnt += 1
		if li[i + 1] == 1000:
			cnt += 1
		cnt += 1
	else:
		a.append(cnt - 1)
		cnt = 0
a.append(cnt - 1)
a.append(0)
print(max(a))


import operator
n = int(input())
a = [int(x) for x in input().strip().split()]
i = 0
c = 0
b = [0]
for i in range(n):
	b.append(a[i] - i - 1)
b.append(1001 - n - 1)
c = dict()
for i in range(len(b)):
	if b[i] in c:
		c[b[i]] += 1
	else:
		c[b[i]] = 1
ans = max(c.items(), key=operator.itemgetter(1))
if ans[1] - 2 >= 0:
	print(ans[1] - 2)
else:
	print(0)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 6
n = I()
a = [0] + L() + [1001]
ans = 0
cnt = 1
for i in range(1, n + 2):
	if a[i] - a[i - 1] == 1:
		cnt += 1
	else:
		ans = max(ans, cnt - 2)
		cnt = 1
print(max(ans, cnt - 2))


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = list(rint())
cnt = 0
if n == 1:
	print(0)
	exit()
if n == 1000:
	print(1000)
	exit()
if n == 2:
	if a[0] == 1 and a[1] == 2:
		print(1)
	elif a[0] == 999 and a[1] == 1000:
		print(1)
	else:
		print(0)
	exit()
ans = 0
flag1 = 0
flag1000 = 0
for i in range(n - 2):
	if a[i] == 1 and a[i + 1] == 2:
		flag1 = 1
	if a[i + 2] == 1000 and a[i + 1] == 999:
		flag1000 = 1
	if a[i + 1] - a[i] == 1 and a[i + 2] - a[i + 1] == 1:
		cnt += 1
		if flag1:
			cnt += 1
		if flag1000:
			cnt += 1
	else:
		cnt = 0
	ans = max(ans, cnt, flag1, flag1000)
	flag1 = 0
	flag1000 = 0
print(ans)


amount = int(input())
array = [int(s) for s in input().split()]
counter = 0
for i in range(len(array)):
	for j in range(len(array)):
		if array[j] - array[i] == j - i and array[j] != 1 and (array[i] != 1) and (array[j] != 1000) and (array[i] != 1000) and (j - i > counter):
			counter = j - i - 1
		elif array[j] - array[i] == j - i and (array[j] == 1 or array[i] == 1 or array[j] == 1000 or (array[i] == 1000)) and (j - i > counter):
			counter = j - i
print(counter)


siz = int(input())
ar = list(map(int, input().split()))
(num, ans) = (0, 0)
for a in range(siz):
	lf = ar[a - 1] if a - 1 > -1 else 1
	rg = ar[a + 1] if a + 1 < siz else 1000
	if num == siz - 1:
		break
	if ar[a] - lf <= 1 and rg - ar[a] <= 1:
		if a == siz - 1:
			num -= 1 if ar[a] != 1000 else 0
		if a == 0:
			num -= 1 if ar[a] != 1 else 0
		num += 1
	else:
		ans = max(ans, num)
		num = 0
print(max(ans, num))


n = int(input())
a = input().split()
ls = [0]
for i in range(n):
	ls.append(int(a[i]))
ls.append(10 ** 3 + 1)
ans = 0
count = 0
for i in range(len(ls)):
	if i == 0:
		count += 1
	elif ls[i] - ls[i - 1] == 1:
		count += 1
	else:
		ans = max(ans, count - 2)
		count = 1
ans = max(ans, count - 2)
print(ans)


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
total_count = 0
local_count = 0
for i in range(1, n + 2):
	if a[i] - a[i - 1] == 1:
		local_count += 1
	else:
		local_count = 0
	total_count = max(local_count - 1, total_count)
print(total_count)


n = int(input())
H = list(map(int, input().split()))
is_1 = 0
max_value = 0
counter = 0
idx = -1
for i in range(1, n):
	if H[i] - H[i - 1] == 1:
		if H[i - 1] == 1:
			counter += 1
		counter += 1
	elif counter:
		if counter - 1 > max_value:
			max_value = counter - 1
		counter = 0
if counter:
	if H[n - 1] == 1000:
		counter += 1
	if counter:
		if counter - 1 > max_value:
			max_value = counter - 1
print(max_value)


(n, a) = (int(input()), [0] + list(map(int, input().split())) + [1001])
a = [a[i] - a[i - 1] for i in range(1, len(a))] + [0]
m = cnt = 0
for i in range(len(a)):
	if a[i] == 1:
		cnt += 1
	elif cnt > 0:
		m = max(m, cnt - 1)
		cnt = 0
print(m)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	n = Int()
	l = List()
	a = [0] + l + [1001]
	ans = []
	c = 0
	for i in range(1, len(a) - 1):
		if a[i + 1] - a[i] == 1 and a[i] - a[i - 1] == 1:
			c += 1
		else:
			ans.append(c)
			c = 0
	else:
		ans.append(c)
	print(max(ans))
solution()


n = int(input())
a = [0] + [int(x) for x in input().split()] + [1001]
opt = 0
for i in range(n + 1):
	j = i
	while j <= n and a[j + 1] == a[j] + 1:
		j += 1
	opt = max(opt, j - i - 1)
print(opt)


n = int(input())
nums = list(map(int, input().split()))
sub_max_seq = []
if n == 1:
	print(0)
else:
	for i in range(n):
		sub_seq = [nums[i]]
		for j in range(i + 1, n):
			if nums[j] - nums[j - 1] == 1:
				sub_seq.append(nums[j])
			else:
				break
		if len(sub_seq) > len(sub_max_seq):
			sub_max_seq = sub_seq
		elif len(sub_seq) == len(sub_max_seq) and 1000 in sub_seq:
			sub_max_seq = sub_seq
	if 1 in sub_max_seq and 1000 in sub_max_seq:
		print(len(sub_max_seq))
	elif 1 in sub_max_seq or 1000 in sub_max_seq:
		print(len(sub_max_seq) - 1)
	else:
		print(max(len(sub_max_seq) - 2, 0))


n = int(input())
a = list(map(int, input().split()))
c = int()
if n == 1:
	print(0)
else:
	if a[0] == 1 and a[1] == 2:
		c = 1
	if a[n - 1] == 1000:
		t = True
	ma = int()
	for i in range(1, n):
		if a[i] - 1 == a[i - 1]:
			c += 1
		else:
			c = 0
		if ma < c:
			ma = int(c)
	if a[n - 1] == 1000 and a[n - 2] == 999:
		c += 1
	if ma < c:
		ma = int(c)
	print(max(0, ma - 1))


import sys
import os
from math import *
input = sys.stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
ip = 0
count = 1
ans = 1
for i in range(n - 1):
	if arr[i] == arr[i + 1] - 1:
		count += 1
	else:
		if arr[ip] == 1:
			if count > 1:
				count += 1
			ip = i + 1
		if ans < count:
			ans = count
		count = 1
if ans <= count:
	if arr[-1] == 1000 or arr[ip] == 1:
		ans = count + 1
	else:
		ans = count
if ans - 2 <= 0:
	print('0')
else:
	print(ans - 2)


n = int(input())
j = list(map(int, input().split()))
best = 0
guys = 1
for i in range(n - 1):
	if j[i + 1] - j[i] == 1:
		guys += 1
	else:
		guys = 1
	if guys > best:
		best = guys
skip = False
if j[0] == 1:
	for i in range(n - 1):
		if i + 2 != j[i + 1]:
			best = max(best, i + 2)
			skip = True
			break
	if not skip and n > 2:
		best = n + 1
if j[-1] == 1000:
	for i in range(n - 1):
		if 1000 - i - 1 != j[-i - 2]:
			best = max(best, i + 2)
			skip = True
			break
	if not skip and n > 2:
		best = n + 1
if j == [1, 2] or j == [999, 1000]:
	print(1)
elif best > 1:
	print(best - 2)
else:
	print(0)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = li()
a = [0] + a + [1001]
ans = 0
i = 0
while i <= n:
	j = i + 1
	while j <= n + 1 and a[j] == a[j - 1] + 1:
		j += 1
	ans = max(ans, j - i - 2)
	i = j
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
mx = 0
for i in range(0, n):
	_mx = 0
	for end in range(i, n):
		if end - i == arr[end] - arr[i]:
			_mx += 1
		else:
			end -= 1
			break
	if end == n:
		end -= 1
	if i == 0 and arr[i] == 1:
		mx = max(mx, _mx - 1)
	elif end == n - 1 and arr[end] == 1000:
		mx = max(mx, _mx - 1)
	else:
		mx = max(mx, _mx - 2)
print(mx)


def main():
	n = int(input())
	a = [0] + [int(c) for c in input().split()]
	a += [1001]
	rem = []
	for i in range(1, len(a) - 1):
		if a[i - 1] + 1 == a[i] == a[i + 1] - 1:
			rem.append(i - 1)
	cnt = 0
	ans = 0
	rem.append(-1)
	for i in range(1, len(rem)):
		if rem[i] == rem[i - 1] + 1:
			cnt += 1
		else:
			cnt += 1
			if cnt > ans:
				ans = cnt
			cnt = 0
		if i == len(rem) - 1 and rem[i] == rem[i - 1] + 1:
			cnt += 1
			if cnt > ans:
				ans = cnt
	print(ans)
main()


import math
n = int(input())
a = list(map(int, input().split()))
num = 1
ans = 0
fi = 0
last = 0
for i in range(1, n):
	if a[i] - a[i - 1] == 1:
		if num == 1:
			fi = a[i - 1]
		num += 1
	else:
		last = a[i - 1]
		if fi == 1 or last == 1000:
			ans = max(ans, num - 1)
		else:
			ans = max(ans, num - 2)
		num = 1
last = a[n - 1]
if fi == 1 or last == 1000:
	ans = max(ans, num - 1)
else:
	ans = max(ans, num - 2)
print(ans)


class Prank:
	n = int(input())
	a = list(map(int, input().split()))
	aux = []
	counter = 1
	for i in range(1, n):
		if a[i] == a[i - 1] + 1:
			counter += 1
		else:
			aux.append(counter)
			counter = 1
	aux.append(counter)
	if aux.index(max(aux)) == 0 and a[0] == 1 or (aux[-1] == max(aux) and a[-1] == 1000):
		print(max(aux) - 1)
	elif max(aux) <= 2:
		print(0)
	else:
		print(max(aux) - 2)


n = int(input())
l = [*map(int, input().split())]
res = i = 0
while i < n:
	j = i + 1
	while j < n and l[j] - l[j - 1] == 1:
		j += 1
	res = max(res, j - i - 2 + int(l[i] == 1) + int(l[j - 1] == 1000))
	i = j
print(min(res, n - 1))


input()
a = [0] + list(map(int, input().split())) + [1001]
(ans, c) = (1, 1)
for i in range(1, len(a)):
	if a[i - 1] + 1 == a[i]:
		c += 1
		if ans < c:
			ans = c
	else:
		c = 1
if ans < c:
	ans = c
if ans == 1:
	ans += 1
print(ans - 2)


n = int(input())
a = list(map(int, input().split()))
a.append(1001)
a.insert(0, 0)
if n == 1:
	print(0)
else:
	k = 1
	ans = 2
	for i in range(1, len(a)):
		if a[i - 1] == a[i] - 1:
			k += 1
		else:
			ans = max(ans, k)
			k = 1
	ans = max(ans, k)
	print(ans - 2)


n = int(input())
a = [int(k) for k in input().split()]
res = 0
for l in range(n):
	for r in range(l + 1, n):
		if a[r] - a[l] == r - l:
			c = r - l - 1
			if a[l] == 1:
				c += 1
			if a[r] == 1000:
				c += 1
			res = max(res, c)
print(res)


(n, rt) = (int(input()), 0)
arr_a = list(map(int, input().split()))
arr_a.insert(0, 0)
arr_a.append(1001)
cal = 0
for i in range(1, n + 1):
	if arr_a[i] - arr_a[i - 1] == 1 and arr_a[i] - arr_a[i + 1] == -1:
		cal += 1
	else:
		rt = max(rt, cal)
		cal = 0
rt = max(rt, cal)
print(rt)


from math import sqrt, pow, ceil
from decimal import *
l1 = int(input())
l2 = input().split()
l2 = [int(i) for i in l2]
l2 = [0] + l2 + [1001]
resp = 0
seg = 0
for i in range(1, l1 + 1):
	if l2[i + 1] - 1 == l2[i] and l2[i - 1] + 1 == l2[i]:
		seg += 1
		resp = max(resp, seg)
	else:
		seg = 0
print(resp)


n = int(input())
elements = [int(x) for x in input().split(' ')]

def group_consecutive(elements):
	consecutive_groups = []
	group = []
	for element in elements:
		if len(group) == 0 or group[-1] + 1 == element:
			group.append(element)
		else:
			consecutive_groups.append(group)
			group = [element]
	if len(group) > 0:
		consecutive_groups.append(group)
	return consecutive_groups
consecutive_groups = group_consecutive(elements)
skipped = list((max(0, len(group) - 2) for group in consecutive_groups))
if len(consecutive_groups) > 0:
	first_group = consecutive_groups[0]
	last_group = consecutive_groups[-1]
	if first_group[0] == 1 and len(first_group) > 1:
		skipped[0] += 1
	if last_group[-1] == 1000 and len(last_group) > 1:
		skipped[-1] += 1
print(max(skipped, default=0))


n = int(input())
a = [0] + [*map(int, input().split())] + [1001]
m = c = 0
for i in range(1, n + 1):
	if a[i] == a[i - 1] + 1 and a[i] == a[i + 1] - 1:
		m += 1
		c = max(c, m)
	else:
		m = 0
print(c)


n = int(input())
arr = list(map(int, input().split()))
if n == 2:
	if arr[-1] - arr[0] > 1:
		print(0)
		exit()
	if arr[1] == 1000:
		print(1)
		exit()
	elif arr[1] == 2:
		print(1)
		exit()
	else:
		print(0)
		exit()
c = 1000
xx = 0
for i in range(n - 1, -1, -1):
	if arr[i] == c:
		xx += 1
		c -= 1
	else:
		break
if xx == n:
	print(xx - 1)
	exit()
cons = 0
first = arr[0]
i = 0
j = 1
cc = 1
mm = 1
maxi = i
maxj = j
while i < n and j < n:
	if first + 1 == arr[j]:
		first = arr[j]
		j += 1
		cc += 1
	else:
		if mm < cc:
			maxj = j
			maxi = i
		mm = max(cc, mm)
		cc = 1
		i = j
		first = arr[i]
		j += 1
if mm < cc:
	maxj = j
	maxi = i
mm = max(cc, mm)
maxj -= 1
if maxi == 0 and maxj == n - 1:
	if arr[0] == 1 and arr[-1] == n:
		print(mm - 1)
		exit()
	if arr[-1] == 1000:
		print(mm - 1)
		exit()
if arr[maxj] == 1000:
	print(mm - 1)
	exit()
if maxi == 0 and arr[0] == 1:
	print(mm - 1)
	exit()
cx = max(xx - 1, mm - 2)
print(max(cx, 0))


n = int(input())
a = [int(x) for x in input().split()]
i = 0
j = 0
c = 0
maxi = 0
while i < n - 1 and j < n - 1:
	if a[j] + 1 == a[j + 1]:
		j += 1
		if j == n - 1:
			c += j - i - 1
			if a[i] == 1:
				c += 1
			if a[j] == 1000:
				c += 1
			maxi = max(c, maxi)
			c = 0
	else:
		if i != j:
			c += j - i - 1
			if a[i] == 1:
				c += 1
			if a[j] == 1000:
				c += 1
			maxi = max(c, maxi)
			c = 0
		j += 1
		i = j
print(maxi)


n = int(input())
a = list(map(int, input().split()))
ma = 0
for i in range(len(a) - 1):
	for j in range(i + 1, len(a)):
		if j - i == a[j] - a[i]:
			if j - i > ma:
				if a[i] == 1 or a[j] == 1000:
					ma = j - i
				else:
					ma = j - i - 1
print(ma)


n = int(input())
a = [0] * (n + 2)
a = [int(i) for i in input().split()]
a.insert(0, 0)
a.insert(n + 1, 1001)
con = 0
ans = 0
for i in range(1, n + 1):
	if a[i] == a[i - 1] + 1 and a[i] == a[i + 1] - 1:
		con += 1
		ans = max(ans, con)
	else:
		con = 0
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
i = 10 ** 6
count = 0
tempans = 0
flag = 0
for j in range(n):
	if arr[j] == j + 1:
		tempans += 1
	else:
		i = j + 1
		flag = 1
		break
if tempans > 0:
	ans = max(tempans - 1, ans)
if i == 10 ** 6 and ans == 0:
	i = 1
while i < n:
	if arr[i] == arr[i - 1] + 1:
		count += 1
	else:
		if count > 0:
			ans = max(ans, count - 1)
		count = 0
	i += 1
if count != 0:
	if arr[-1] == 1000:
		ans = max(count, ans)
	else:
		ans = max(count - 1, ans)
print(ans)


n = int(input())
A = list(map(int, input().split()))
a = 0
ans = 0
for i in range(1, n):
	if A[i] - A[i - 1] == 1:
		a += 1
	else:
		ans = max(a + 1, ans)
		a = 0
ans = max(ans, a + 1)
if ans <= 1:
	print(0)
elif A[0] == 1 and A[ans - 1] == ans or (A[n - 1] == 1000 and A[n - ans] == 1000 - ans + 1):
	print(ans - 1)
else:
	print(ans - 2)


n = int(input())
res = 1
cur_res = 1
nex_mb = 1
for ai in map(int, input().split()):
	if ai == nex_mb:
		cur_res += 1
	else:
		if cur_res > res:
			res = cur_res
		cur_res = 1
		nex_mb = ai
	nex_mb += 1
if nex_mb == 1001:
	cur_res += 1
if cur_res > res:
	res = cur_res
if res <= 2:
	print('0')
else:
	print(res - 2)


n = int(input())
nS = [int(x) for x in input().split()]
maxVal = 0
if n != 1:
	val = 0
	for i in range(1, n):
		dif = nS[i] - nS[i - 1] == 1
		if dif:
			val += 2 if nS[i - 1] == 1 or nS[i] == 1000 else 1
			maxVal = max(maxVal, val)
		else:
			val = 0
print(max(maxVal - 1, 0))


n = int(input())
a = [0] + list(map(int, input().split())) + [1001]
mx = 1
p = 1
for i in range(1, n + 2):
	if a[i] == a[i - 1] + 1:
		p += 1
		mx = max(p, mx)
	else:
		p = 1
print(max(0, mx - 2))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	sa = []
	s = 0
	e = 0
	for i in range(n - 1):
		if a[i] == a[i + 1] - 1:
			e = i + 1
		else:
			sa.append(a[s:e + 1])
			s = i + 1
			e = i + 1
	else:
		sa.append(a[s:e + 1])
	j = 0
	m = 0
	for i in range(len(sa)):
		if len(sa[i]) > m:
			m = len(sa[i])
			j = i
		elif len(sa[i]) == m:
			if sa[i][m - 1] == 1000:
				j = i
	if sa[j][0] == 1 or sa[j][m - 1] == 1000:
		print(m - 1)
	elif m < 3:
		print(0)
	else:
		print(m - 2)


N = int(input())
A = list(map(int, input().split()))
if N == 1:
	print(0)
elif N == 2:
	if A == [1, 2] or A == [999, 1000]:
		print(1)
	else:
		print(0)
else:
	A.append(-10 ** 5)
	N += 1
	num = 0
	pre = A[0]
	i = 0
	while i < N:
		pre = A[i]
		for j in range(i + 1, N):
			if A[j] != pre + 1:
				if i == 0 and A[i] == 1 and (j - i >= 2):
					num = max(num, j - i - 1)
				elif j == N - 1 and A[j - 1] == 1000 and (j - i >= 2):
					num = max(num, j - i - 1)
				elif j - i >= 3:
					num = max(num, j - i - 2)
				i = j - 1
				break
			pre = A[j]
		i += 1
	print(num)


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : list(input())
ips = lambda : input().split()
t = ii()
a = ll()
i = 0
ans = 0
while i < t:
	j = i + 1
	k = i
	while j < t:
		if a[j] - 1 == a[k]:
			j += 1
			k += 1
		else:
			break
	if a[j - 1] == 1000 or a[i] == 1:
		ans = max(ans, j - i - 1)
	else:
		ans = max(ans, j - i - 2)
	i = j
print(ans)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = [0] + list(mints()) + [1001]
c = 0
p = -2
m = 0
for i in a:
	if p + 1 == i:
		c += 1
		m = max(m, c)
		p += 1
	else:
		p = i
		c = 1
		m = max(m, 1)
print(max(0, m - 2))


__author__ = 'tanunia'
from sys import stdin
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
a.insert(0, 0)
a.append(1001)
max_cnt = 0
cur_cnt = 0
for i in range(1, len(a) - 1):
	if a[i] - 1 == a[i - 1] and a[i] + 1 == a[i + 1]:
		cur_cnt += 1
	else:
		if max_cnt < cur_cnt:
			max_cnt = cur_cnt
		cur_cnt = 0
if max_cnt < cur_cnt:
	max_cnt = cur_cnt
print(max_cnt)