#include <bits/stdc++.h>
using namespace std;
int n, m;
int have[32];
int ori_have[32];
int need[32];
int x[1000001];
bool check(int till) {
  for (int i = 0; i <= 30; i++) have[i] = ori_have[i];
  memset(need, 0, sizeof(need));
  for (int i = 1; i <= till; i++) need[x[i]]++;
  for (int i = 30; i >= 0; i--) {
    if (have[i] < need[i]) return false;
    int lefts = 2 * (have[i] - need[i]);
    if (i > 0) have[i - 1] += min(lefts, 10000000);
  }
  return true;
}
int MAIN() {
  while (cin >> n >> m) {
    memset(have, 0, sizeof(have));
    memset(need, 0, sizeof(need));
    for (int i = 1; i <= n; i++) {
      int t;
      cin >> t;
      for (int j = 0; j <= 30; j++)
        if ((t & (1 << j)) > 0) have[j]++;
    }
    for (int i = 0; i <= 30; i++) ori_have[i] = have[i];
    for (int i = 1; i <= m; i++) {
      cin >> x[i];
    }
    sort(x + 1, x + 1 + m);
    int lef = 0, rig = m + 1, mid;
    while (rig - lef > 1) {
      mid = (lef + rig) / 2;
      if (check(mid))
        lef = mid;
      else
        rig = mid;
    }
    cout << lef << endl;
  }
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
