#include <iostream>
using namespace std;
#include <bits/stdc++.h>

int main() {
	// your code goes here
	
	vector<int>arr={1,2,1,0,1,1,0};
	int n=arr.size();
	
	int k;
	cin>>k;
	int window_sum=0;
	int i=0,j=0;
	int max_length=INT_MIN;
	while(j<n)
	{
		window_sum+=arr[j];
		
		while(i<=j && window_sum<=k)
		 {
		 	max_length=max(max_length,j-i+1);
		 	window_sum=window_sum-arr[i];
		 	i++;
		 }
		j++;
	}
	if(max_length==INT_MIN)
	 {
	 	cout<<-1;
	 }
	 else
	  {
	  	cout<<max_length;
	  }
//	cout<<max_length;
	
	
	return 0;
}