#include <bits/stdc++.h>
using namespace std;
int ara[1000006], val[1000006], b[1000006];
bool chck(int n, int mid) {
  vector<int> v1, v2;
  for (int i = 0; i < n; i++) b[i] = ara[i];
  for (int i = mid - 1; i >= 0; i--) {
    int x = val[i], cnt = 0;
    while (i >= 0 && val[i] == x) cnt++, i--;
    i++;
    v1.emplace_back(x);
    v2.emplace_back(cnt);
  }
  for (int i = 0; i < v1.size(); i++) {
    int cnt = v2[i];
    for (int j = 0; j < n && cnt; j++)
      while (b[j] >= v1[i] && cnt) b[j] -= v1[i], cnt--;
    if (cnt) return 0;
  }
  return 1;
}
int main() {
  int n, m, x;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &ara[i]);
  for (int i = 0; i < m; i++) scanf("%d", &x), val[i] = (1 << (x));
  sort(ara, ara + n, greater<int>()), sort(val, val + m);
  int lo = 1, hi = m, res = 0;
  while (lo <= hi) {
    int mid = (lo + hi) >> 1;
    if (chck(n, mid))
      res = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  printf("%d\n", res);
  return 0;
}
