#include <bits/stdc++.h>
using namespace std;
int monsters[100005];
int special[2005];
bool is_special[200005];
int dp[100005][2];
int monst_bound[100005];
int la[400055];
int comp[100005];
int beg[100005];
int en[100005];
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> monsters[i];
  for (int i = 1; i <= m; i++) {
    cin >> special[i];
    is_special[special[i]] = 1;
  }
  sort(monsters + 1, monsters + n + 1);
  sort(special + 1, special + m + 1);
  for (int i = 1; i <= n; i++)
    monst_bound[i] =
        lower_bound(special + 1, special + m + 1, monsters[i]) - special;
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    if (monsters[i] - monsters[i - 1] == 1)
      comp[i] = comp[i - 1];
    else
      comp[i] = cnt++;
  }
  for (int i = n; i >= 1; i--) beg[comp[i]] = i;
  for (int i = 1; i <= n; i++) en[comp[i]] = i;
  for (int g = n; g >= 1; g--) {
    for (int y = 0; y < 2; y++) {
      int ent = en[comp[g]];
      int net = beg[comp[g] + 1];
      int re = upper_bound(special + 1, special + m + 1, monsters[ent]) -
               special - monst_bound[g];
      dp[g][y] = re + max(dp[net][0], dp[net][1]);
      if (y == 1 && monsters[g + 1] - monsters[g] == 1)
        dp[g][y] = max(dp[g][y], dp[g + 1][y]);
      if (y == 0) {
        int cur = monst_bound[g];
        if (cur == m + 1) continue;
        for (int z = cur; z <= m; z++) {
          int cha = special[z] - monsters[g] + g;
          if (cha > n) break;
          int ne = beg[comp[cha] + 1];
          dp[g][y] = max(dp[g][y], z - cur + 1 + max(dp[ne][0], dp[ne][1]));
        }
      } else {
        int cur = monst_bound[g];
        if (cur == m + 1) continue;
        for (int z = cur; z <= m; z++) {
          int va = special[z] - g + 200005;
          if (la[va] == 0) continue;
          int ne = la[va];
          dp[g][y] = max(dp[g][y], monst_bound[ne] - z + dp[ne][0]);
        }
      }
    }
    la[monsters[g] - g + 200005] = g;
  }
  cout << max(dp[1][0], dp[1][1]) << '\n';
  return 0;
}
