#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  k = 2 * k;
  char a[4][4];
  int no = 0;
  for (int i = 1; i <= 9; i++) {
    int coun = 0;
    for (int j = 0; j < 4; j++) {
      for (int l = 0; l < 4; l++) {
        if (i == 1) cin >> a[j][l];
        if ((a[j][l] - '0') == i) ++coun;
      }
    }
    if (coun > k) no = 1;
  }
  if (no == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
