#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int a[N], f[105], g[105];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < m; ++i) {
    int x;
    scanf("%d", &x);
    ++g[x];
  }
  for (int i = 0; i < 31; ++i) {
    int j = 1 << i;
    for (int k = 0; k < n; ++k)
      if ((a[k] & j) != 0) ++f[i];
  }
  int ans = 0;
  for (int i = 0; i < 31; ++i) {
    while (f[i] < g[i]) {
      int j = i + 1;
      while (j < 31 && f[j] == 0) ++j;
      if (j == 31) break;
      for (int t = i; t < j; ++t) ++f[t];
      ++f[i];
      --f[j];
    }
    if (g[i] > f[i]) g[i] = f[i];
    ans += g[i];
  }
  cout << ans << endl;
  return 0;
}
