#include <bits/stdc++.h>
using namespace std;
const int N = 30 + 10;
int n, m, t, a[N], b[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    for (int j = 0; (1 << j) <= t; j++)
      if (t & (1 << j)) a[j]++;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &t);
    b[t]++;
  }
  int ans = 0;
  for (int i = 0; i < 30; i++) {
    bool cont = true;
    while (b[i] && cont) {
      int x = min(a[i], b[i]);
      b[i] -= x;
      a[i] -= x;
      ans += x;
      if (!b[i]) break;
      cont = false;
      for (int j = i + 1; j < 30; j++)
        if (a[j]) {
          a[j]--;
          a[j - 1] += 2;
          cont = true;
          break;
        }
    }
  }
  printf("%d\n", ans);
  return 0;
}
