#include <bits/stdc++.h>
using namespace std;
const int MXN = 2000010;
int N, M;
int A[MXN], B[MXN], T[32] = {};
void init() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%d", A + i);
  for (int i = 1; i <= M; i++) scanf("%d", B + i), T[B[i]]++;
}
namespace solve {
long long answer = 0;
int sat[MXN], m = 0, p = 1;
void solve() {
  for (int b = 30; b >= 0; b--) {
    for (int i = 1; i <= N; i++) {
      int x = min(T[b], A[i] >> b);
      A[i] -= x << b;
      T[b] -= x;
      for (int i = 0; i < x; i++) sat[++m] = b;
    }
    while (T[b] && p <= m && sat[p] > b) {
      A[++N] = 1 << sat[p++];
      int x = min(T[b], A[N] >> b);
      A[N] -= x << b;
      T[b] -= x;
      for (int i = 0; i < x; i++) sat[++m] = b;
    }
  }
  cout << m - p + 1 << endl;
}
}  // namespace solve
int main() {
  init();
  solve::solve();
  return 0;
}
