#include <bits/stdc++.h>
using namespace std;
void out(const vector<long long>& x) {
  for (int i = 0; i < x.size(); ++i) cerr << x[i] << ' ';
  cerr << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(32);
  vector<long long> b(32);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < a.size(); ++j) {
      if (x & 1) ++a[j];
      x /= 2;
    }
  }
  for (int i = 0; i < m; ++i) {
    int x;
    scanf("%d", &x);
    b[x]++;
  }
  int res = 0;
  for (int i = 0; i < b.size(); ++i)
    if (b[i] > 0) {
      for (int j = i; j < a.size(); ++j) {
        long long mul = 1LL << (j - i);
        int t = min(a[j] * mul, b[i]);
        res += t;
        b[i] -= t;
        long long x = (t + mul - 1) / mul;
        long long rem = x * mul - t;
        a[j] -= x;
        for (int l = j - 1; l >= i; --l) {
          mul /= 2;
          long long add = rem / mul;
          a[l] += add;
          rem -= add * mul;
        }
        if (b[i] == 0) break;
      }
    }
  cout << res << endl;
  return 0;
}
