#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long LL;

class CardStraights
{
public:
	int longestStraight(vector <int> cards) 
	{
		int jok = count(cards.begin(), cards.end(), 0);

		set<int> cs(cards.begin(), cards.end());
		cs.erase(0);
		if( cs.empty() )
			return jok; // Ouggggggggg

		int ans = 0;
		for(set<int>::iterator it=cs.begin(); it!=cs.end(); ++it)
			ans = max(ans, asLongAsPossible(it, cs.end(), jok));
		return ans;
	}

	int asLongAsPossible(set<int>::iterator it, set<int>::iterator end, int jok)
	{
		int b = *it;
		int e = *it;
		for(++it; it!=end; e=*it++)
			if( *it-e-1 <= jok )
				jok -= *it-e-1;
			else
				break;
		int nAfter = min(1000000-e, jok);
		e += nAfter;
		b -= min(b-1, jok-nAfter);
		return e-b+1;
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arr0[] = {0,6,5,10,3,0,11}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 5; verify_case(0, Arg1, longestStraight(Arg0)); }
	void test_case_1() { int Arr0[] = {100,100,100,101,100,99,97,103}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; verify_case(1, Arg1, longestStraight(Arg0)); }
	void test_case_2() { int Arr0[] = {0,0,0,1,2,6,8,1000}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; verify_case(2, Arg1, longestStraight(Arg0)); }
	void test_case_3() { int Arr0[] = {1,9,5,7,3,4,0,0,0,10}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 10; verify_case(3, Arg1, longestStraight(Arg0)); }
	void test_case_4() { int Arr0[] = {0,0,999999}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; verify_case(4, Arg1, longestStraight(Arg0)); }

// END CUT HERE
};
// BEGIN CUT HERE 
int main() { CardStraights().run_test(-1); }
// END CUT HERE
