#include <bits/stdc++.h>
using namespace std;
const int N = 1121111;
inline int cmp(const void *pa, const void *pb) {
  return -(*((int *)pa)) + (*((int *)pb));
}
int a[N];
int b[N];
long long int numa[32];
long long int numb[32];
long long int ta[32];
long long int tb[32];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  memset(numa, 0, sizeof(numa));
  memset(numb, 0, sizeof(numb));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 31; j >= 0; j--)
      if (a[i] & (1 << j)) numa[j]++;
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    numb[b[i]]++;
  }
  int left = 0, right = m + 1;
  while (left + 1 < right) {
    int mid = (left + right) >> 1;
    int ans = 0;
    for (int i = 0; i < 32; i++) {
      ta[i] = numa[i];
      tb[i] = 0;
    }
    int temp = mid;
    for (int i = 0; i < 32; i++)
      if (numb[i] <= temp) {
        temp -= numb[i];
        tb[i] = numb[i];
      } else {
        tb[i] = temp;
        temp = 0;
      }
    for (int i = 31; i >= 0; i--) {
      if (ta[i] < tb[i]) {
        ans += ta[i];
        ta[i] = 0;
      } else {
        ta[i] -= tb[i];
        ans += tb[i];
      }
      if (i) ta[i - 1] += 2 * ta[i];
    }
    if (ans == mid)
      left = mid;
    else
      right = mid;
  }
  cout << left << '\n';
}
