#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  long long n, m, temp, cnt = 0, sum = 0;
  cin >> n >> m;
  vector<long long> a(n), b;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  for (long long i = 0; i < m; ++i) {
    cin >> temp;
    if (temp == 0)
      ++cnt;
    else
      b.push_back(temp);
  }
  m = b.size();
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long i = 0, j = 0, cur = a[0], ans = 0;
  while (i < n && j < m) {
    long long len = pow(2, b[j]);
    if (len > cur) {
      ans += min(cnt, cur);
      sum -= min(cnt, cur);
      cnt -= min(cnt, cur);
      ++i;
      if (i < n) cur = a[i];
    } else {
      if (sum - len < cnt) {
        ans += min(sum, cnt);
        cnt -= min(sum, cnt);
        break;
      }
      sum -= len;
      cur -= len;
      a[i] = cur;
      ++ans;
      ++j;
    }
  }
  ans += min(sum, cnt);
  cout << ans << '\n';
  return 0;
}
