#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 20;
const int OFF = (1 << LOG);
int n, m, x[N], y[N], pref[N], pref2[N], nw[5000][2], ol[5000][2],
    dp[2000][200][2];
vector<int> cen;
vector<pair<int, int> > v;
inline int sum(int l, int r) {
  if (r < l) return 0;
  return pref[r] - (l ? pref[l - 1] : 0);
}
inline int sum2(int l, int r) {
  if (r < l) return 0;
  l = max(l, 0);
  r = min(r, N - 1);
  return pref2[r] - (l ? pref2[l - 1] : 0);
}
inline int get(int x, int y) {
  int l;
  if (x < y) {
    l = v[y].first - sum(x, y - 1);
  } else {
    l = v[y].first + sum(y, x - 1);
  }
  return sum2(l, l + v[x].second - 1);
}
int f(int x, int cn, int fl) {
  if (cn == cen.size()) return 0;
  if (x == n) return 0;
  if (dp[x][cn][fl] != -1) return dp[x][cn][fl];
  int ret = f(x + 1, cn, 1) + get(x, cen[cn]);
  if (x > cen[cn] || !fl) ret = max(ret, f(x, cn + 1, 0));
  return dp[x][cn][fl] = ret;
}
void iterativno() {
  for (int x = n - 1; x >= 0; x--) {
    for (int cn = cen.size() - 1; cn >= 0; cn--) {
      if (x < cen[cn]) {
        nw[cn][1] = ol[cn][1] + get(x, cen[cn]);
      } else {
        nw[cn][1] = max(ol[cn][0], ol[cn][1]) + get(x, cen[cn]);
      }
      if (x <= cen[cn]) nw[cn][0] = max(nw[cn][0], nw[cn][1]);
      nw[cn][0] = max(nw[cn][0], nw[cn + 1][0]);
    }
    for (int i = 0; i < cen.size(); i++)
      for (int j = 0; j < 2; j++) swap(nw[i][j], ol[i][j]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", x + i);
  }
  sort(x, x + n);
  v.push_back({x[0], 1});
  for (int i = 1; i < n; i++) {
    if (v.back().first + v.back().second == x[i])
      v.back().second++;
    else
      v.push_back({x[i], 1});
  }
  n = v.size();
  v.push_back({INF, INF});
  for (int i = 0; i < n; i++) {
    pref[i] = (i ? pref[i - 1] : 0) + v[i].second;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", y + i);
    pref2[y[i]]++;
  }
  for (int i = 1; i < N; i++) pref2[i] += pref2[i - 1];
  sort(y, y + m);
  int j = 0;
  for (int i = 0; i < m; i++) {
    while (j < n && v[j].first + v[j].second - 1 < y[i]) j++;
    if (j != n) {
      if (v[j].first > y[i] && j != 0) cen.push_back(j - 1);
      cen.push_back(j);
    }
  }
  sort(cen.begin(), cen.end());
  cen.erase(unique(cen.begin(), cen.end()), cen.end());
  iterativno();
  printf("%d\n", ol[0][0]);
}
