#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int MAXN = 1000010;
const int N = 30;
int a[MAXN], b[MAXN];
int cp[N];
int n, m;
bool solve(int len) {
  int i, j;
  memset(cp, 0, N * 4);
  for (i = 0; i < len; ++i) {
    ++cp[b[i]];
  }
  for (j = n; j--;) {
    int ln = a[j];
    for (i = N; i--;) {
      int count = min(cp[i], ln >> i);
      cp[i] -= count;
      ln -= count << i;
    }
  }
  for (i = 0; i < N; ++i) {
    if (cp[i] > 0) {
      return 0;
    }
  }
  return 1;
}
bool check1(int len) {
  int i, j;
  memset(cp, 0, N * 4);
  for (i = 0; i < len; ++i) {
    ++cp[b[i]];
  }
  for (j = n; j--;) {
    int ln = a[j];
    for (i = N; i--;) {
      int count = min(ln >> i, cp[i]);
      cp[i] -= count;
      ln -= count << i;
    }
  }
  for (i = 0; i < N; ++i) {
    if (cp[i] > 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) a[i] = in();
  for (int i = 0; i < m; ++i) b[i] = in();
  sort(a, a + n);
  sort(b, b + m);
  int left = 0, right = m + 1;
  for (; left + 1 < right;) {
    int c = (left + right) / 2;
    (solve(c) ? left : right) = c;
  }
  printf("%d\n", left);
  return 0;
}
