#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int n = 0;
    int q = 0;
    cin >> n;
    
    int s[n];
    for (int i = 0; i < n; i++) {
        scanf("%d",&s[i]);
    }
    cin >> q;
    int t[q];
    for (int i = 0; i < q; i++) {
        scanf("%d",&t[i]);
    }
    int sum = 0;
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (s[j] == t[i]) {
                sum++;
                break;
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;	
	cin >> n;	
	
	multiset<int> s;
	rep(i,n){
		int x;
		cin >> x;
		auto itr = s.lower_bound(x);
		if(itr == s.begin()){
			s.insert(x);
			continue;
		}
		itr--;
		s.erase(itr);
		s.insert(x);
	}
	cout << s.size() << endl;
}
