public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		while (in.hasNext()) {
			int n = in.nextInt();
			int[] v = new int[n];
			int[] r = new int[n];
			for (int i = 0; i < n; i++)
				v[i] = r[n - i - 1] = in.nextInt();
			int[] lisA = lis(v);
			int[] lisB = lis(r);
			int max = 0;
			for (int i = 0; i < n; i++) 
				max = Math.max(max, Math.min(lisA[i], lisB[n - i - 1]));
			out.append((max * 2) - 1 + "\n");
		}
		System.out.print(out);
	}