#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e6 + 3;
vector<int> a(33, 0), b(max_n);
bool possible(int x) {
  vector<int> s(32), need(32, 0);
  s = a;
  for (int i = 0; i < x; ++i) need[b[i]]++;
  for (int i = 30; i >= 0; --i) {
    if (s[i] < need[i]) return false;
    int left = 2 * (s[i] - need[i]);
    if (i > 0) s[i - 1] = s[i - 1] + min(left, 10000000);
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  b.resize(m);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    for (int j = 0; j < 31; ++j) {
      if ((x & (1ll << j)) > 0) {
        a[j]++;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  sort(b.begin(), b.end());
  long long l = 0, r = m + 1;
  while (r - l > 1) {
    long long mid = (l + r) >> 1;
    if (possible(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << endl;
}
