#include <bits/stdc++.h>
using namespace std;
const int inv = numeric_limits<int>::max();
const int minv = numeric_limits<int>::min();
const int max_n = 1000010;
const int max_m = 1000010;
int n, m;
int a[max_n], b[max_m];
int sz[max_n], nsz;
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  make_heap(a, a + n);
  int t;
  for (int j = 0; j < m; ++j) {
    scanf("%d", &t);
    b[j] = (1 << t);
  }
  sort(b, b + m);
  reverse(b, b + m);
  nsz = 0;
  for (int j = 0; j < m; ++j) {
    if (a[0] >= b[j]) {
      t = a[0] - b[j];
      pop_heap(a, a + n);
      sz[nsz++] = b[j];
      a[n - 1] = t;
      push_heap(a, a + n);
    }
  }
  int res = 0;
  reverse(sz, sz + nsz);
  reverse(b, b + m);
  int k = 0;
  for (int j = 0; j < m; ++j) {
    while ((k < nsz) and sz[k] < b[j]) ++k;
    if (k == nsz) break;
    sz[k] -= b[j];
    ++res;
  }
  printf("%d\n", res);
  return 0;
}
