#include <bits/stdc++.h>
using namespace std;
void Yahia74() {
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e6 + 74, OO = 0x3f3f3f3f;
int a[N];
int main() {
  Yahia74();
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    bitset<32> mask(x);
    for (int j = 0; j < ((int)(mask).size()); j++) {
      if (mask[j]) mp[1 << j]++;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    a[i] = 1 << a[i];
  }
  sort(a, a + m);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (mp[a[i]] > 0) {
      mp[a[i]]--;
      ans++;
    } else {
      for (long long j = a[i] << 1LL; j < (long long)1e9; j <<= 1LL) {
        if (mp[j] > 0) {
          mp[j]--;
          j -= a[i];
          ans++;
          bitset<32> mask(j);
          for (int k = 0; k < ((int)(mask).size()); k++) {
            if (mask[k]) mp[1 << k]++;
          }
          break;
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
