#include <bits/stdc++.h>
using namespace std;
long q, p;
vector<long> v;
long calc[100], n, m;
long ans;
void build(long q) {
  for (int pw = 30; pw >= 0; --pw) {
    if (q >= (1 << pw)) {
      calc[pw]++;
      q -= (1 << pw);
    }
  }
}
void solve(long a, long b) {
  calc[b]--;
  for (int i = b - 1; i >= a; --i) {
    calc[i]++;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> q;
    build(q);
  }
  for (int i = 0; i < m; i++) {
    cin >> p;
    v.push_back(p);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    for (int j = v[i]; j <= 30; j++) {
      if (calc[j] > 0) {
        solve(v[i], j);
        ++ans;
        break;
      }
    }
  }
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}
