#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 100;
int n, m;
int a[N], b[N];
int c[33];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    for (int j = 0; j < 32; ++j)
      if ((a[i] >> j) & 1) c[j]++;
  }
  for (int i = 0; i < m; ++i) scanf("%d", b + i);
  sort(b, b + m);
  int ans;
  for (ans = 0; ans < m; ++ans) {
    if (c[b[ans]]) {
      c[b[ans]]--;
      continue;
    }
    int x;
    for (x = b[ans]; x < 32; ++x)
      if (c[x]) break;
    while (x != b[ans] && c[x]) {
      c[x]--;
      x--;
      c[x] += 2;
    }
    if (c[b[ans]])
      c[b[ans]]--;
    else
      break;
  }
  cout << ans << "\n";
  return 0;
}
