#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
using namespace std;
const int MOD = 1000000007;
int a[1000005], b, fr[31], comp[31];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    for (int j = 0; j <= 30; ++j)
      if ((a[i] >> j) & 1) comp[j]++;
  }
  for (int i = 0; i < m; ++i) cin >> b, fr[b]++;
  int ans = 0;
  for (int i = 0; i < 31; ++i) {
    while (fr[i]) {
      bool f = 0;
      if (comp[i]) {
        comp[i]--;
        ans++, f = 1, fr[i]--;
      } else {
        for (int j = i + 1; j <= 30; ++j)
          if (comp[j]) {
            comp[j]--;
            ans++, f = 1, fr[i]--;
            for (int z = i; z < j; ++z) comp[z]++;
            break;
          }
      }
      if (!f) break;
    }
    if (fr[i]) break;
  }
  cout << ans << "\n";
  return 0;
}
