#include <bits/stdc++.h>
using namespace std;
int a[1000010], b[1000010], sum[30], use[30];
bool check() {
  long long rem = 0;
  for (int i = 29; i >= 0; --i) {
    rem = 2 * rem + sum[i] - use[i];
    if (rem < 0) return false;
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = (int)(0); i < (int)(n); ++i) scanf("%d", a + i);
  for (int i = (int)(0); i < (int)(m); ++i) scanf("%d", b + i);
  sort(a, a + n);
  sort(b, b + m);
  for (int i = (int)(0); i < (int)(n); ++i)
    for (int j = (int)(0); j < (int)(30); ++j)
      if (a[i] & (1 << j)) ++sum[j];
  int lo = 0, hi = m + 1;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    fill_n(use, 30, 0);
    for (int i = (int)(0); i < (int)(mid); ++i) ++use[b[i]];
    (check() ? lo : hi) = mid;
  }
  printf("%d\n", lo);
}
