#include <bits/stdc++.h>
using namespace std;
int findFirstBit(int x, int num = 0) {
  for (int i = num;; ++i)
    if (x & (1 << i)) return i;
  return -1;
}
vector<stack<int> > a;
int main() {
  a.assign(30, stack<int>());
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[findFirstBit(x)].push(x);
  }
  vector<int> kol(31, 0);
  for (int i = 0; i < m; ++i) {
    int x;
    scanf("%d", &x);
    kol[x]++;
  }
  stack<pair<int, int> > st;
  for (int i = 29; i >= 0; --i)
    for (int vvv = 0; vvv < kol[i]; ++vvv) st.push(make_pair(i, 1));
  int ans = 0;
  int last = 0;
  while (!st.empty()) {
    pair<int, int> p = st.top();
    st.pop();
    int r = p.first;
    if (r >= 30) break;
    while (last < r) {
      while (!a[last].empty()) {
        int x = a[last].top();
        a[last].pop();
        x -= (1 << last);
        if (x) a[findFirstBit(x, last)].push(x);
      }
      ++last;
    }
    if (!a[r].empty()) {
      int x = a[r].top();
      ans += p.second;
      a[r].pop();
      x -= (1 << r);
      if (x) a[findFirstBit(x, r)].push(x);
      continue;
    }
    vector<int> kols(1, p.second);
    while (!st.empty() && st.top().first == r) {
      kols.push_back(st.top().second);
      st.pop();
    }
    if (kols.size() % 2 > 0) kols.push_back(0);
    for (int i = (int)kols.size() - 2; i >= 0; i -= 2)
      st.push(make_pair(r + 1, kols[i] + kols[i + 1]));
  }
  printf("%d\n", ans);
  return 0;
}
