#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
using namespace std;
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1], b[m + 1], cnt[33] = {0};
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= m; i++) cin >> b[i];
  sort(b + 1, b + m + 1);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < 32; j++) {
      if (a[i] & (1 << j)) {
        cnt[j]++;
      }
    }
  }
  long long idx = 0;
  for (long long i = 1; i <= m; i++) {
    for (long long j = b[i]; j < 32; j++) {
      if (cnt[j]) {
        ans++;
        cnt[j]--;
        for (long long k = j - 1; k >= b[i]; k--) cnt[k]++;
        break;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
