#include <bits/stdc++.h>
using namespace std;
int in[1000010];
int tt[30];
int n;
bool chk() {
  for (int i = (n - 1); i > int(0 - 1); i -= 1) {
    int a = in[i];
    for (int z = (29); z > int(0 - 1); z -= 1)
      while (tt[z] && (a >> z)) tt[z]--, a -= 1 << z;
  }
  bool ki = 1;
  for (int i = (0); i < int(30); i += 1) ki &= !tt[i];
  return ki;
}
int main() {
  int tab[30] = {0};
  int m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < int(n); i += 1) scanf("%d", in + i);
  sort(in, in + n);
  int a;
  for (int j = (0); j < int(m); j += 1) {
    scanf("%d", &a);
    tab[a]++;
  }
  int s = 0, e = m - 1, mid, last = m;
  while (s <= e) {
    mid = (s + e) >> 1;
    memcpy(tt, tab, sizeof(tab));
    int aa = mid, z;
    for (int i = 29; aa; i--) {
      z = (((aa) < (tt[i])) ? (aa) : (tt[i]));
      tt[i] -= z;
      aa -= z;
    }
    if (chk())
      last = mid, e = mid - 1;
    else
      s = mid + 1;
  }
  printf("%d", m - last);
  return 0;
}
