#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1010000;
int n, m, x, ans, a[40], b[40];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &x);
    for (int j = 0; j < (int)31; j++)
      if (x & (1 << (j))) b[j]++;
  }
  for (int i = 0; i < (int)m; i++) scanf("%d", &x), a[x]++;
  for (int i = 0; i < (int)31; i++) {
    for (int j = i; j < (int)31; j++) {
      if (!a[i]) break;
      int rem = a[i] % (1 << (j - i));
      int blk = (a[i] >> (j - i)) + !!rem;
      if (blk > b[j]) {
        a[i] -= b[j] << (j - i);
        ans += b[j] << (j - i);
        b[j] = 0;
      } else {
        ans += a[i];
        a[i] = 0;
        b[j] -= blk;
        if (rem) {
          rem = (1 << (j - i)) - rem;
          for (int k = 0; k < (int)j - i; k++)
            if (rem & (1 << (k))) b[i + k]++;
        }
      }
    }
  }
  printf("%d\n", ans);
}
