#include <bits/stdc++.h>
using namespace std;
int a[1000100], b[1000100], cnt[32];
int solve(int n, int m) {
  int i, j, k, ret = 0;
  memset(cnt, 0, sizeof(cnt));
  for (i = 0; i < n; ++i) {
    for (j = 0; (1 << j) <= a[i]; ++j) {
      if (a[i] & (1 << j)) ++cnt[j];
    }
  }
  sort(b, b + m);
  for (i = 0; i < m; ++i) {
    for (j = b[i]; j < 32 && !cnt[j]; ++j)
      ;
    if (j == 32) break;
    ++ret;
    --cnt[j];
    for (k = b[i]; k < j; ++k) ++cnt[k];
  }
  return ret;
}
int main() {
  int n, m, i;
  while (~scanf("%d %d", &n, &m)) {
    for (i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (i = 0; i < m; ++i) scanf("%d", &b[i]);
    printf("%d\n", solve(n, m));
  }
  return 0;
}
