#include <bits/stdc++.h>
using namespace std;
string dp[2001][2001];
int op(string &a, string &b) {
  int ans = 0;
  for (int i = 0; i < 7; i++) {
    if (a[i] == '1' && b[i] == '0')
      return -1;
    else if (a[i] == '0' && b[i] == '1')
      ans++;
  }
  return ans;
}
string helper(vector<string> &v, vector<string> &aux, int k, int i = 0) {
  if (i == v.size()) {
    if (k == 0)
      return "";
    else
      return "$";
  }
  if (dp[i][k] != "0") return dp[i][k];
  for (int j = 9; j >= 0; j--) {
    int s = op(v[i], aux[j]);
    if (s == -1 or s > k) continue;
    string after = helper(v, aux, k - s, i + 1);
    if (after != "$") return dp[i][k] = to_string(j) + after;
  }
  return dp[i][k] = "$";
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<string> v;
  for (int i = 0; i <= 2000; i++) {
    for (int j = 0; j <= 2000; j++) {
      dp[i][j] = "0";
    }
  }
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  vector<string> aux({"1110111", "0010010", "1011101", "1011011", "0111010",
                      "1101011", "1101111", "1010010", "1111111", "1111011"});
  string s = helper(v, aux, k);
  if (s == "$")
    cout << -1 << endl;
  else
    cout << s << endl;
}
