#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> a;
vector<long long> place;
void use(long long x) {
  long long pi = 0;
  long long p2 = 1;
  while (p2 <= x) {
    if (x & p2) a[pi]++;
    pi++;
    p2 <<= 1;
  }
}
bool works(long long v) {
  vector<long long> ta = a;
  vector<long long> tput(30);
  for (long long i = 0; i < v; i++) tput[place[i]]++;
  for (long long i = ta.size() - 1; i >= 1; i--) {
    ta[i] -= tput[i];
    if (ta[i] < 0) return false;
    ta[i - 1] += 2 * ta[i];
  }
  ta[0] -= tput[0];
  if (ta[0] < 0) return false;
  return true;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  cin >> n >> m;
  a.resize(30);
  place.resize(m);
  long long t;
  for (long long i = 0; i < n; i++) {
    cin >> t;
    use(t);
  }
  for (long long i = 0; i < m; i++) cin >> place[i];
  sort(place.begin(), place.end());
  long long s, e;
  s = 0;
  e = m;
  while (s < e) {
    long long v = (s + e + 1) / 2;
    if (works(v))
      s = v;
    else
      e = v - 1;
  }
  cout << s << endl;
}
