#include <bits/stdc++.h>
using namespace std;
void da(int *a, int s, int e) {
  for (int i = s; i < e; i++) cout << a[i] << " ";
}
void db(string s) { cout << s << '\n'; }
void cp(int *a, int *b, int n) {
  for (int i = 0; i < n; i++) b[i] = a[i];
}
void de(int a) { cout << a << " <\n"; }
const int N = 1e6 + 10, sn = 375, LOG = 33, MOD = 1e9 + 7;
int n, m, a[LOG], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, cnt = 0;
    cin >> x;
    while (x) {
      a[cnt] += (x & 1);
      x /= 2;
      cnt++;
    }
  }
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(b, b + m);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    for (int j = b[i]; j < LOG; j++) {
      if (a[j] > 0) {
        if (j == b[i])
          a[j]--;
        else {
          a[j]--;
          for (int k = 0; k < j; k++) a[k]++;
        }
        ans++;
        break;
      }
    }
  }
  cout << ans;
}
