#include <bits/stdc++.h>
using namespace std;
const int MX = 1000005, INF = 1000000000, mod = 1000000009;
const long long int LINF = 1000000000000000000ll;
const double eps = 1e-9;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int b[35], c[35];
int main() {
  int n, m, a, x, ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    for (int i = 0; i < 32; i++) {
      if (a == 0) break;
      c[i] += (a & 1);
      a >>= 1;
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &a);
    b[a]++;
  }
  for (int i = 0; i < 32; i++) {
    if (b[i] == 0) continue;
    ans += min(b[i], c[i]);
    b[i] -= c[i];
    c[i] = 0;
    if (b[i] > 0) {
      while (b[i]) {
        x = i;
        while (x < 32 && c[x] <= 0) x++;
        if (c[x] <= 0) break;
        c[x]--;
        for (int j = x - 1; j >= i; j--) c[j]++;
        b[i]--;
        ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
