#include <bits/stdc++.h>
using namespace std;
const int N = 31;
int a[1000010];
long long cnt1[N + 10];
long long cnt2[N + 10];
long long cnt3[N + 10];
long long cnt4[N + 10];
int b[1000010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  int c = 0;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (N); ++j)
      if ((a[i] >> j) & 1) cnt1[j]++;
  }
  for (int i = (0); i < (m); ++i) {
    scanf("%d", &b[i]);
    cnt4[b[i]]++;
  }
  int res = 0;
  int l = 0, r = m;
  while (l <= r) {
    int mid = (l + r) / 2;
    int k = N - 1;
    int now = mid;
    for (int j = (0); j < (N); ++j) {
      cnt3[j] = ((now < cnt4[j]) ? (now) : (cnt4[j]));
      now -= cnt3[j];
    }
    for (int j = (0); j < (N); ++j) cnt2[j] = cnt1[j];
    bool f = true;
    for (int i = N - 1; i >= 0; --i) {
      cnt2[i] += cnt2[i + 1] + cnt2[i + 1];
      if (cnt2[i] < cnt3[i]) {
        f = false;
        break;
      } else
        cnt2[i] -= cnt3[i];
    }
    if (f) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << res << endl;
  return 0;
}
