#include <bits/stdc++.h>
using namespace std;
long long n, m, A[2000010], B[2000010], S1[32], T1[32], P[32];
inline bool check(long long x) {
  for (long long i = 0; i <= 30; i++) T1[i] = P[i];
  memset(S1, 0, sizeof S1);
  for (long long i = 1; i <= x; i++) S1[B[i]]++;
  for (long long i = 30; i >= 0; i--) {
    if (T1[i] < S1[i]) return 0;
    T1[i] -= S1[i];
    if (i) T1[i - 1] += T1[i] * 2;
  }
  return 1;
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &A[i]);
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j <= 30; j++)
      if (A[i] & (1 << j)) P[j]++;
  for (long long i = 1; i <= m; i++) scanf("%lld", &B[i]);
  sort(B + 1, B + 1 + m);
  long long L = 0, R = m, Ans = 0;
  while (L <= R) {
    long long mid = (L + R) >> 1;
    if (check(mid))
      Ans = mid, L = mid + 1;
    else
      R = mid - 1;
  }
  cout << Ans << endl;
  return 0;
}
