#include <bits/stdc++.h>
using namespace std;
const int maxl = 1000 * 1000 + 1;
const int maxlg = 31;
int a[maxlg];
vector<int> b[maxlg];
int n, m;
int ans;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j < maxlg; j++) a[j] += (x & (1 << j)) / (1 << j);
  }
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    b[x].push_back(1);
  }
  for (int i = 0; i < maxlg - 1; i++) {
    sort(b[i].begin(), b[i].end());
    while (!b[i].empty() && a[i]) {
      ans += b[i].back();
      b[i].pop_back();
      a[i]--;
    }
    while (b[i].size() >= 2) {
      int x = b[i].back();
      b[i].pop_back();
      int y = b[i].back();
      b[i].pop_back();
      b[i + 1].push_back(x + y);
    }
    if (b[i].size()) b[i + 1].push_back(b[i][0]), b[i].pop_back();
  }
  for (int i = 0; i < maxlg - 1; i++)
    if (b[i].size()) {
      for (int j = i; j < maxlg; j++)
        if (a[j]) {
          a[j]--;
          if (j != i) a[j - 1]++;
          ans++;
          break;
        }
    }
  printf("%d\n", ans);
}
