#include <bits/stdc++.h>
using namespace std;
int n, m, mi[40], a[2000000], b[3000000], l, r, mid, ans;
vector<int> sz[40];
bool check(int mid) {
  int i, zhi = 30;
  for (i = 0; i <= 30; i++) sz[i].clear();
  for (i = 1; i <= n; i++) {
    sz[((31 - __builtin_clz(a[i])))].push_back(a[i]);
  }
  zhi = 30;
  for (i = mid; i >= 1; i--) {
    while (zhi >= 0) {
      if (sz[zhi].size() == 0) {
        zhi--;
        continue;
      }
      if (mi[zhi] < b[i]) return false;
      int si = sz[zhi].size();
      int sum = sz[zhi][si - 1];
      sz[zhi].pop_back();
      sum -= b[i];
      if (sum == 0) break;
      int ww = ((31 - __builtin_clz(sum)));
      sz[ww].push_back(sum);
      break;
    }
    if (zhi == -1) return false;
  }
  return true;
}
int main() {
  int i;
  scanf("%d%d", &n, &m);
  mi[0] = 1;
  for (i = 1; i <= 30; i++) mi[i] = mi[i - 1] * 2;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= m; i++) scanf("%d", &b[i]);
  sort(a + 1, a + 1 + n);
  for (i = 1; i <= m; i++) b[i] = mi[b[i]];
  sort(b + 1, b + 1 + m);
  int l, r;
  l = 1;
  r = m;
  ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%d", ans);
}
