#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000000;
const int max_m = 1000000;
const int max_bit = 32;
int n, m, v, a[max_bit] = {0}, b[max_bit] = {0}, i, j, r = 0;
int main() {
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &v);
    for (j = 0; j < max_bit; j++)
      if ((1 << j) & v) a[j]++;
  }
  for (i = 0; i < m; i++) scanf("%d", &v), b[v]++;
  while (true) {
    i = 0;
    while (i < max_bit && b[i] == 0) i++;
    b[i]--;
    while (i < max_bit && a[i] == 0) a[i]++, i++;
    if (i == max_bit) break;
    a[i]--;
    r++;
  }
  printf("%d\n", r);
  return 0;
}
