#include <bits/stdc++.h>
using namespace std;
int const R = 31;
int n, m;
int A[R];
int B[R];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  int temp, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    int k = 0;
    while (temp) {
      A[k++] += temp & 1;
      temp >>= 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> temp;
    B[temp]++;
  }
  while (true) {
    int i = 0;
    while (i < R && !B[i]) i++;
    B[i]--;
    while (i < R && !A[i]) A[i++]++;
    if (i == R) break;
    A[i]--;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}
