#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream input("Bai4_16.inp");
ofstream output("Bai4_16.out");
int m, n;
vector <int> a;
vector <int> b;
int res = 0;

int binarySearch(int item, int low, int high)
{
	if (high <= low)
		return (item > b[low]) ? (low + 1) : low;

	int mid = (low + high) / 2;

	if (item == b[mid])
		return mid + 1;

	if (item > b[mid])
		return binarySearch(item, mid + 1, high);
	return binarySearch(item, low, mid - 1);
}

int main()
{
	input >> m >> n;
	a = vector <int> (m);
	b = vector <int> (n);
	for (int i = 0; i < m; ++i)
	{
		input >> a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		input >> b[i];
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < m; ++i)
	{
		int pos = binarySearch(a[i], 0, b.size() - 1);
		if (pos != 0 && pos != b.size())
		{
			for (int j = pos; j < b.size(); ++j)
			{
				if (b[j] != b[i])
				{
					b.erase(b.begin() + j);
					break;
				}
			}
			for (int j = pos - 1; i >= 0; --j)
			{
				if (b[j] != b[i])
				{
					b.erase(b.begin() + j);
					break;
				}
			}
			++res;
		}
	}
	output << res;
	input.close();
	output.close();
	return 0;
}