#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int INF = 1e9 + 7;
long long a[MAXN], b[MAXN], cnt[30];
bool check(int mid) {
  vector<long long> temp(30);
  for (int i = 0; i < 30; ++i) {
    temp[i] = cnt[i];
  }
  int pointer = 29;
  for (int i = mid - 1; i >= 0 && pointer >= 0; --i) {
    if (b[i] == pointer) {
      if (temp[pointer] < 1) return false;
      --temp[pointer];
    } else if (b[i] < pointer) {
      --pointer;
      temp[pointer] += temp[pointer + 1] * 2;
      i++;
    } else
      return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  sort(b, b + m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 30; ++j) {
      if ((a[i] & (1 << j))) ++cnt[j];
    }
  }
  int l = 0, r = m + 1;
  while (r - l > 1) {
    int mid = l + (r - l) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l;
}
