#include <bits/stdc++.h>
using namespace std;
map<string, int> mapper;
map<string, vector<int>> dist;
void solve(string start) {
  dist[start] = vector<int>(10, 10);
  queue<pair<string, int>> q;
  q.push(pair<string, int>(start, 0));
  set<string> visited;
  visited.insert(start);
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    if (mapper.count(cur.first)) {
      int num = mapper[cur.first];
      dist[start][num] = cur.second;
    }
    for (int i = 0; i < ((int)(cur.first).size()); i++) {
      if (cur.first[i] != '0') continue;
      string ncur = cur.first;
      ncur[i] = '1';
      if (!visited.count(ncur)) {
        visited.insert(ncur);
        q.push(pair<string, int>(ncur, cur.second + 1));
      }
    }
  }
}
int n, k;
vector<vector<int>> memo;
vector<string> digits;
int go(int a, int b) {
  if (a == n) return b == 0 ? 0 : -1;
  if (memo[a][b] != -2) return memo[a][b];
  int i = -1;
  for (i = 9; i >= 0; i--) {
    int d = dist[digits[a]][i];
    if (d == 10) continue;
    if (d > b) continue;
    if (go(a + 1, b - d) >= 0) break;
  }
  return memo[a][b] = i;
}
int main() {
  mapper["0010010"] = 1;
  mapper["1011101"] = 2;
  mapper["1011011"] = 3;
  mapper["0111010"] = 4;
  mapper["1101011"] = 5;
  mapper["1101111"] = 6;
  mapper["1010010"] = 7;
  mapper["1111111"] = 8;
  mapper["1111011"] = 9;
  mapper["1110111"] = 0;
  for (int i = 0; i < (1 << 7); i++) {
    bitset<7> bs(i);
    solve(bs.to_string());
  }
  cin >> n >> k;
  memo = vector<vector<int>>(n + 1, vector<int>(k + 1, -2));
  digits = vector<string>(n);
  for (int i = 0; i < (n); i++) cin >> digits[i];
  if (go(0, k) == -1)
    cout << -1 << '\n';
  else {
    int b = k;
    for (int a = 0; a < (n); a++) {
      cout << memo[a][b];
      b -= dist[digits[a]][memo[a][b]];
    }
    cout << '\n';
  }
  return 0;
}
