/*
  Name:
  Copyright: DHKHTN - DHQGHN
  Author: Nguyen Dinh Nhat
  Date: 26/07/10 21:40
  Description: 
		SPSEQ
		https://v...content-available-to-author-only...j.pl/problems/SPSEQ/
*/


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

#define TI freopen("test.inp","rt",stdin)

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) for(int i=0;i<n;i++)


#define NMAX 100009

int A[NMAX],L[3][NMAX],startof[NMAX];
int N,m=0,n=0;
void decode (){
	scanf ("%d",&N);
	FOR (i,1,2*N+1){
		scanf ("%d",&A[i]);
	}
	
}

// tim j sao cho khi them phan tu aj vao cuoi danh sach thi ta duoc do dai day tang 

int tim_j (int i){
	int truoc=0,sau=m+1,hientai;
	while (sau!=truoc+1){
		hientai=(truoc+sau)/2;
		if (A[i]>A[startof[hientai]]) truoc=hientai;
		else sau=hientai;
	}
	return truoc;
}

void SPSEQ (){
	int j,k;
	FOR (i,1,N){
		j=tim_j (i);
		k=j+1;
		L[0][i]=k;
		if (k>m){
			m=k; startof[k]=i;
		}
		else if (A[i]<A[startof[k]]){
			startof[k]=i;
		}
	}
	int t,rs=0;
	FOR (i,1,N){
		t=L[0][i];
		FOR (j,i+1,N)
			if (t==1) break;
			else if (L[0][j]==t-1){
					t--;
					L[0][i]++;
					rs=max(rs,L[0][i]);
				}
	}
	cout<<rs;
}


//#include <conio.h>
int main ()
{
//	TI;
	decode ();
	SPSEQ ();	
//	getch ();
    return 0;
}
