#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 333;
const long long linf = 1e18 + 333;
const int N = 1e5 + 5;
int n, m, s[N], b[N], sum[N], seq[N], beq[N], dp[2][N];
pair<int, int> a[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", s + i);
  for (int i = 1; i <= m; i++) scanf("%d", b + i);
  sort(s + 1, s + n + 1);
  sort(b + 1, b + m + 1);
  int sz = 0;
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j + 1 <= n and s[j + 1] - s[j] == 1) j++;
    a[++sz] = pair<int, int>(s[i], s[j]);
    i = j;
  }
  n = sz;
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + (a[i].second - a[i].first + 1);
  int j = 0;
  for (int i = 0; i < N; i++) {
    while (j + 1 <= n and sum[j + 1] <= i) j++;
    seq[i] = j;
  }
  j = n + 1;
  for (int i = N - 1; i; i--) {
    while (j - 1 >= 1 and sum[j - 1] >= i) j--;
    beq[i] = j;
  }
  int it = 1;
  for (int i = 1; i <= n; i++) {
    while (it <= m and b[it] < a[i].first) it++;
    for (int j = it - 1; j >= 1; j--) {
      int id = sum[i - 1] - (a[i].first - b[j]);
      if (id < 0) break;
      id = seq[id];
      dp[0][i] = max(dp[0][i], (it - j) + dp[1][id]);
    }
    dp[0][i] = max(dp[0][i], dp[1][i - 1]);
    while (it <= m and b[it] <= a[i].second) {
      dp[0][i]++;
      it++;
    }
    for (int j = it; j <= m; j++) {
      int id = sum[i] + (b[j] - a[i].second);
      if (id >= N or beq[id] == n + 1) break;
      id = beq[id];
      dp[1][id] = max(dp[1][id], (j - it + 1) + dp[0][i]);
    }
    dp[1][i] = max(dp[1][i], dp[0][i]);
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
