#include <bits/stdc++.h>
using namespace std;
long long int freq[100];
long long int mxbase = 0;
long long int mx(long long int a, long long int b) {
  if (a <= b) {
    return b;
  } else {
    return a;
  }
}
void binary(long long int x) {
  long long int p = ceil(log2(x));
  mxbase = mx(mxbase, p);
  long long int i = 0;
  while (i <= p) {
    if (x % 2) freq[i]++;
    x /= 2;
    i++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, m;
  cin >> n >> m;
  long long int x;
  vector<long long int> sally(m);
  for (int i = 0; i < n; ++i) {
    cin >> x;
    binary(x);
  }
  for (int i = 0; i < m; ++i) {
    cin >> sally[i];
  }
  sort(sally.begin(), sally.end());
  long long int ans = 0, z = 0;
  for (int j = 0; j < m && z <= mxbase;) {
    if (freq[z] && sally[j] <= z) {
      ans++;
      j++;
      freq[z]--;
      if (z > sally[j]) {
        long long int rem = pow(2, z) - pow(2, sally[j]);
        binary(rem);
        z = 0;
      }
    } else
      z++;
  }
  cout << ans;
  return 0;
}
