#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 100;
int a[maxn], b[maxn], n, m, cnt[40];
void add(int x) {
  int rem = 0;
  while (x > 0) cnt[rem++] += (x % 2), x /= 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) add(a[i]);
  sort(b + 1, b + m + 1);
  for (int i = 1; i <= m; i++) {
    for (int j = b[i]; j <= 30; j++) {
      if (cnt[j] > 0) {
        cnt[j]--;
        if (j == b[i]) break;
        for (int l = j - 1; l >= cnt[b[i]]; l--) cnt[l] = 1;
        break;
      }
      if (j == 30) {
        cout << i - 1 << endl;
        return 0;
      }
    }
  }
  cout << m << endl;
  return 0;
}
