#include <bits/stdc++.h>
using namespace std;
const int N = 1100000;
int n, m, nr[34], pp, rez, nu[34];
char a[16000000];
inline int ter() {
  int r = 0;
  while (a[pp] >= '0' && a[pp] <= '9') r = r * 10 + a[pp++] - '0';
  ++pp;
  return r;
}
int main() {
  int i, j, k;
  cin >> n >> m;
  cin.get();
  cin.getline(a, 16000000);
  for (i = 1; i <= n; ++i) {
    int x;
    x = ter();
    for (j = 0; j <= 30; ++j)
      if (x & (1 << j)) ++nr[j];
  }
  cin.getline(a, 16000000);
  pp = 0;
  for (i = 1; i <= m; ++i) {
    int x;
    x = ter();
    nu[x]++;
  }
  for (i = 0; i <= 30; ++i) {
    for (j = 1; j <= nu[i]; ++j) {
      for (k = i; k <= 30; ++k)
        if (nr[k]) {
          nr[k]--;
          ++rez;
          for (int l = k - 1; l >= i; --l) nr[l]++;
          break;
        }
    }
  }
  cout << rez;
  return 0;
}
