#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline string tostr(const T &x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
inline long long parse(const string &s) {
  stringstream ss(s);
  long long x;
  ss >> x;
  return x;
}
const long double EPS = 1e-12;
const int INF = 1000 * 1000 * 1000;
const char CINF = 102;
const long long LINF = INF * 1ll * INF;
const long double DINF = 1e200;
const long double PI = 3.1415926535897932384626433832795l;
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long powmod(long long a, long long p, long long m) {
  long long r = 1;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
vector<pair<int, int> > go[110000];
int solve(vector<int> &A, vector<int> &B) {
  int n = ((int)(A).size());
  int m = ((int)(B).size());
  sort((A).begin(), (A).end());
  sort((B).begin(), (B).end());
  vector<int> Al(n), Ar(n);
  Al[0] = 0;
  for (int i = 1; i < n; ++i) {
    if (A[i] == A[i - 1] + 1)
      Al[i] = Al[i - 1] + 1;
    else
      Al[i] = 0;
  }
  Ar[n - 1] = 0;
  for (int i = n - 2; i >= 0; --i) {
    if (A[i] == A[i + 1] - 1)
      Ar[i] = Ar[i + 1] + 1;
    else
      Ar[i] = 0;
  }
  vector<int> Ai(n);
  vector<int> Bi(m);
  for (int i = 0; i < (((int)(B).size())); ++i) {
    Bi[i] = (int)(lower_bound((A).begin(), (A).end(), B[i]) - A.begin());
  }
  for (int i = 0; i < (((int)(A).size())); ++i) {
    Ai[i] = (int)(lower_bound((B).begin(), (B).end(), A[i]) - B.begin());
  }
  vector<int> on(n + 1);
  for (int i = 0; i < (((int)(A).size())); ++i) {
    on[i] = Ai[i] < m && B[Ai[i]] == A[i];
  }
  for (int i = 0; i < (n); ++i) {
    go[i].clear();
  }
  for (int b = 0; b < (((int)(B).size())); ++b) {
    int a = Bi[b];
    if (a == n) break;
    if (b + 1 < m && B[b + 1] <= A[a]) continue;
    for (int bb = b; bb >= 0; --bb) {
      int aa = a - (A[a] - B[bb]);
      if (aa < 0) break;
      if (a + Ar[a] == aa - Al[aa]) continue;
      go[aa - Al[aa]].push_back(make_pair(a + Ar[a], b - bb + 1));
    }
  }
  vector<int> D(n + 1), S(n + 1);
  for (int a = n - 1; a >= 0; --a) {
    D[a] = D[a + 1];
    S[a] = max(S[a + 1] + on[a + 1], D[a + 1]);
    int b = Ai[a];
    if (b < m && !(a + 1 < n && A[a + 1] <= B[b])) {
      for (int bb = b; bb < m; ++bb) {
        int aa = a + (B[bb] - A[a]);
        if (aa >= n) break;
        S[a] = max(S[a], D[aa + Ar[aa] + 1] + (bb - b + 1) - on[a]);
      }
    }
    for (int i = 0; i < (((int)(go[a]).size())); ++i) {
      int aa = go[a][i].first;
      int d = go[a][i].second;
      D[a] = max(D[a], S[aa] + d);
    }
    D[a] = max(D[a], S[a] + on[a]);
  }
  return D[0];
}
void gen(vector<int> &A, vector<int> &B, int lim) {
  for (int i = 0; i < (((int)(A).size())); ++i) {
    A[i] = rand() % (lim - ((int)(A).size()) + 1);
  }
  for (int i = 0; i < (((int)(B).size())); ++i) {
    B[i] = rand() % (lim - ((int)(B).size()) + 1);
  }
  sort((A).begin(), (A).end());
  sort((B).begin(), (B).end());
  for (int i = 0; i < (((int)(A).size())); ++i) {
    A[i] += i;
  }
  for (int i = 0; i < (((int)(B).size())); ++i) {
    B[i] += i;
  }
}
vector<int> C;
int ans;
void tryans(vector<int> &B) {
  int r = 0;
  for (int i = 0; i < (((int)(C).size())); ++i) {
    int t = lower_bound((B).begin(), (B).end(), C[i]) - B.begin();
    if (t < ((int)(B).size()) && B[t] == C[i]) ++r;
  }
  ans = max(ans, r);
}
void doit(int a, vector<int> &A, vector<int> &B) {
  if (a == ((int)(A).size())) {
    tryans(B);
    return;
  }
  int sz0 = ((int)(C).size());
  for (int b = a + 1; b <= ((int)(A).size()); ++b) {
    for (int k = a + 1; k <= b; ++k) {
      if (a == -1 && k > a + 1) continue;
      if (b == ((int)(A).size()) && k < b) continue;
      if (a > -1 && b < ((int)(A).size()) && A[k - 1] + 1 == A[k]) continue;
      for (int i = 0; i < (k - a - 1); ++i) {
        C.push_back(A[a] + i + 1);
      }
      for (int i = b - k; i >= (b == ((int)(A).size()) ? 1 : 0); --i) {
        C.push_back(A[b] - i);
      }
      doit(b, A, B);
      C.erase(C.begin() + sz0, C.end());
    }
  }
}
int brute(vector<int> &A, vector<int> &B) {
  ans = 0;
  C.clear();
  doit(-1, A, B);
  return ans;
}
void stress() {
  for (int s = 2; s <= 100; ++s) {
    for (int lim = 1; lim <= s; ++lim) {
      for (int n = 1; n <= lim && n + lim <= s; ++n) {
        int m = s - lim - n;
        if (m <= lim) {
          cerr << lim << ' ' << n << ' ' << m << endl;
          vector<int> A(n);
          vector<int> B(m);
          for (int qqq = 0; qqq < (1000); ++qqq) {
            gen(A, B, lim);
            int b = brute(A, B);
            int r = solve(A, B);
            if (b != r) {
              cout << "failed " << lim << ' ' << n << ' ' << m << ' ' << qqq
                   << ": " << b << ' ' << r << endl;
              cout << n << ' ' << m << endl;
              for (int i = 0; i < (((int)(A).size())); ++i) {
                cout << A[i] << ' ';
              }
              cout << endl;
              for (int i = 0; i < (((int)(B).size())); ++i) {
                cout << B[i] << ' ';
              }
              return;
            }
          }
        }
      }
    }
  }
  cout << "passed";
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n), B(m);
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < (m); ++i) {
    scanf("%d", &B[i]);
  }
  cout << solve(A, B);
  return 0;
}
