#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, a;
  scanf("%d %d", &m, &a);
  vector<int> mems;
  vector<int> arrs;
  int odd_places = 0, y;
  for (int i = 0; i < m; i++) {
    scanf("%d", &y);
    if (y % 2) {
      odd_places++;
      if (y > 1) {
        y--;
        mems.push_back(y);
      }
    } else
      mems.push_back(y);
  }
  sort(mems.begin(), mems.end());
  int odds = 0, x;
  for (int i = 0; i < a; i++) {
    scanf("%d", &x);
    x = powl(2, x);
    if (x == 1)
      odds++;
    else
      arrs.push_back(x);
  }
  sort(arrs.begin(), arrs.end());
  int cnt = 0, rem_ones = 0;
  if (odd_places >= odds)
    cnt += odds;
  else {
    cnt += odd_places;
    rem_ones = odds - odd_places;
  }
  for (int i = 0; i < mems.size(); i++) {
    if (rem_ones) {
      if (rem_ones >= mems[i]) {
        cnt += mems[i];
        rem_ones -= mems[i];
        mems[i] = 0;
      } else {
        cnt += rem_ones;
        mems[i] -= rem_ones;
        rem_ones = 0;
      }
    } else
      break;
  }
  int last = 0;
  for (int i = 0; i < arrs.size(); i++) {
    int it =
        lower_bound(mems.begin() + last, mems.end(), arrs[i]) - mems.begin();
    if (it < mems.size()) {
      cnt++;
      mems[it] -= arrs[i];
      last = it;
    } else
      break;
  }
  printf("%d\n", cnt);
  return 0;
}
