import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; int min = 1; int low = 0; for(int a_i=0; a_i < n; a_i++){ a[a_i] = in.nextInt(); } //another method is just to use a hashmap and map the number of times number appears //find the largest one and add the next consecutive value //because if each value appears once the max is always 2 numbers in a set to keep the <= 1 difference Arrays.sort(a); int count = 1; int prev = 0; //previous number count int curr = 1; //current number count for(int i = 1; i < n; i++){ if(a[i] == a[i-1]){ curr++; if((prev + curr) > count){ count = prev + curr; } } else if(a[i] - 1 == a[i-1]){ prev = curr; curr = 1; if((prev + curr) > count){ count = prev + curr; } } else{ prev = 0; curr = 1; } } System.out.println(count); } }