#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int n, m, a[N], b[N];
vector<int> v;
bool check(int x) {
  v.clear();
  for (int i = 0; i < n; i++) v.push_back(a[i]);
  for (int i = x - 1; i >= 0; i--) {
    int f = i;
    while (i >= 0 && b[i] == b[f]) i--;
    int t = f - i;
    for (int j = 0; j < n; j++) {
      if (v[j] >= b[f]) v[j] -= b[f], j--, t--;
      if (t == 0) break;
    }
    if (t != 0) return false;
    i++;
  }
  return true;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
    b[j] = 1LL << b[j];
  }
  sort(b, b + m);
  sort(a, a + n);
  int l = 0, r = m + 1;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << "\n";
  return 0;
}
