#include <bits/stdc++.h>
using namespace std;
vector<string> charInt = {"1110111", "0010010", "1011101", "1011011",
                          "0111010", "1101011", "1101111", "1010010",
                          "1111111", "1111011"};
vector<string> inp;
vector<vector<int> > dp;
bool match(int i_char, int j_inp) {
  for (int i = 0; i < 7; ++i)
    if (inp[j_inp][i] == '1' && charInt[i_char][i] == '0') return false;
  return true;
}
int diff(int i_char, int j_inp) {
  int a = 0;
  for (int i = 0; i < 7; ++i)
    if (inp[j_inp][i] == '0' && charInt[i_char][i] == '1') a++;
  return a;
}
int func(int index, int k, vector<int> &ans) {
  if (k < 0) return 1;
  if (index >= inp.size()) return ((k == 0) + 1);
  if (dp[index][k] != 0) {
    return dp[index][k];
  }
  dp[index][k] = 1;
  for (int i = 9; i >= 0; --i) {
    if (!match(i, index) || diff(i, index) > k) continue;
    int num = diff(i, index);
    ans.push_back(i);
    if (func(index + 1, k - num, ans) == 1)
      ans.pop_back();
    else {
      dp[index][k] = 2;
      break;
    }
  }
  return dp[index][k];
}
int main(void) {
  long long n, k;
  cin >> n >> k;
  inp = vector<string>(n);
  dp = vector<vector<int> >(n, vector<int>(k + 1, 0));
  vector<int> ans;
  for (int i = 0; i < n; ++i) cin >> inp[i];
  if (func(0, k, ans) == 1)
    cout << -1;
  else
    for (int x : ans) cout << x;
  cout << endl;
}
