#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, m;
long long a[1000005], b[1000005], cnt[35], cnt2[35], cnt3[35];
bool check(int md) {
  memset(cnt3, 0, sizeof(cnt3));
  memset(cnt2, 0, sizeof(cnt2));
  for (int i = 0; i < md; i++) {
    cnt2[b[i]]++;
  }
  for (int i = 0; i < 32; i++) cnt3[i] = cnt[i];
  for (int i = 31; i >= 0; i--) {
    if (cnt2[i] > cnt3[i]) {
      return false;
    }
    cnt3[i] -= cnt2[i];
    if (i > 0) cnt3[i - 1] += cnt3[i] * 2;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", a + i);
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 32; j++) {
      if (a[i] & (1 << j)) {
        cnt[j]++;
      }
    }
  }
  for (int i = 0; i < m; i++) scanf("%I64d", b + i);
  sort(b, b + m);
  long long lb = 0, rb = m + 1;
  while (lb + 1 < rb) {
    int md = (lb + rb) >> 1;
    if (check(md))
      lb = md;
    else
      rb = md;
  }
  printf("%I64d\n", lb);
  return 0;
}
