#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  vector<int> pwrs(31, 0);
  for (int i = 0; i < 31; i++) {
    pwrs[i] = power(2, i);
  }
  int ans = 0;
  vector<int> toadd(m);
  int ones = 0;
  for (int i = 0; i < m; i++) {
    cin >> toadd[i];
    toadd[i] = pwrs[toadd[i]];
    if (toadd[i] == 1) ones++;
  }
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (ones > 0 && v[i] % 2 == 1) {
      v[i]--;
      ones--;
      j++;
      ans++;
    }
  }
  sort(v.begin(), v.end());
  sort(toadd.begin(), toadd.end());
  int ptr = 0;
  for (; j < m;) {
    while (ptr < n && v[ptr] < toadd[j]) ptr++;
    if (ptr == n) break;
    v[ptr] -= toadd[j];
    j++;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}
