#include <bits/stdc++.h>
using i64 = long long;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    std::cin >> n;
    std::set<std::tuple<int, int, int>> s;
    std::vector<std::pair<int, int>> a(n);
    for (auto &[x, y] : a) {
        std::cin >> x >> y;
    }
    sort(a.begin(), a.end());
    s.emplace(std::max(abs(a[n - 1].first - a[0].first), abs(a[n - 1].second - a[0].second)), 0, n - 1);
    s.emplace(std::max(abs(a[n - 2].first - a[0].first), abs(a[n - 2].second - a[0].second)), 0, n - 2);
    s.emplace(std::max(abs(a[n - 1].first - a[1].first), abs(a[n - 1].second - a[1].second)), 1, n - 1);
    std::vector<int> id(n);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int i, int j){
        if (a[i].second == a[j].second) return a[i].first < a[j].first;
        return a[i].second < a[j].second;
    });
    s.emplace(std::max(abs(a[id[n - 1]].first - a[id[0]].first), abs(a[id[n - 1]].second - a[id[0]].second)), id[0], id[n - 1]);
    s.emplace(std::max(abs(a[id[n - 2]].first - a[id[0]].first), abs(a[id[n - 2]].second - a[id[0]].second)), id[0], id[n - 2]);
    s.emplace(std::max(abs(a[id[n - 1]].first - a[id[1]].first), abs(a[id[n - 1]].second - a[id[1]].second)), id[1], id[n - 1]);
    auto x = s.end();
    x--;
    x--;
    std::cout << std::get<0>(*x) << "\n";
    return 0;
}
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<int> A(N), B(M);
	for (int &a: A) cin >> a;
	for (int &b: B) cin >> b;
	
	vector<vector<int>> dp(N + 1, vector<int> (M + 1, 0));
	for (int i = 0; i <= N; i++) dp[i][0] = -i;
	for (int i = 0; i <= M; i++) dp[0][i] = -i;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			dp[i][j] = max(dp[i - 1][j - 1] - 1  + (A[i - 1] == B[j - 1]), max(dp[i - 1][j] - 1, dp[i][j - 1] - 1));
		}
	}
	cout << abs(dp[N][M]) << endl;
}