#include <bits/stdc++.h>
using namespace std;
int di[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int ar[] = {6, 2, 5, 5, 4, 5, 5, 3, 7, 6};
vector<pair<int, pair<int, string>>> v;
int dp[2005][2005];
string seq[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
int solve(int idx, int rem) {
  if (idx == v.size()) {
    if (!rem) return 1;
    return 0;
  }
  int &ret = dp[idx][rem];
  if (~ret) return ret;
  ret = 0;
  for (int i = 0; i < 10; i++) {
    int st = 0, f = 1;
    for (int j = 0; j < 7; j++) {
      if (seq[i][j] == '1' && v[idx].second.second[j] == '0')
        st++;
      else if (seq[i][j] != v[idx].second.second[j]) {
        f = 0;
        break;
      }
    }
    if (f) {
      if (st <= rem) ret |= solve(idx + 1, rem - st);
    }
  }
  return ret;
}
void print(int idx, int rem) {
  if (idx == v.size()) return;
  int val = 0, tmp = 0;
  for (int i = 0; i < 10; i++) {
    int st = 0, f = 1;
    for (int j = 0; j < 7; j++) {
      if (seq[i][j] == '1' && v[idx].second.second[j] == '0')
        st++;
      else if (seq[i][j] != v[idx].second.second[j]) {
        f = 0;
        break;
      }
    }
    if (f && rem - st >= 0 && solve(idx + 1, rem - st)) val = i, tmp = st;
  }
  printf("%d", val);
  print(idx + 1, rem - tmp);
}
int main() {
  int tc = 1;
  map<string, int> mp;
  for (int i = 0; i < 10; i++) mp[seq[i]] = i;
  while (tc--) {
    memset(dp, -1, sizeof dp);
    int n, k;
    scanf("%d %d", &n, &k);
    v.clear();
    v.resize(n);
    for (int i = 0; i < n; i++) {
      char inp[10];
      scanf("%s", inp);
      v[i].first = mp[inp];
      v[i].second.first = count(inp, inp + 7, '1');
      v[i].second.second = inp;
    }
    int ans = solve(0, k);
    if (!ans)
      printf("-1\n");
    else {
      print(0, k);
    }
  }
}
