#include <bits/stdc++.h>
using namespace std;
int n;
string res;
map<string, int> stv;
map<int, string> vts;
vector<string> a, s({"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"});
vector<vector<int>> dp;
int cnt(string f, string t) {
  int res = 0;
  for (int i = 0; i < 7; i++) {
    if (f[i] != t[i]) {
      ++res;
      if (f[i] == '1') return -1;
    }
  }
  return res;
}
int bt(int in, int k) {
  if (k < 0) return 0;
  if (in >= n) return k == 0;
  int& dpv = dp[in][k];
  if (dpv == 1) return 0;
  for (int i = 9; i >= 0; i--) {
    int c = cnt(a[in], vts[i]);
    if (c >= 0 && bt(in + 1, k - c)) {
      res.push_back(i + '0');
      return 1;
    }
  }
  dpv = 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> n >> k;
  a.resize(n);
  dp.assign(n, vector<int>(k + 1));
  for (auto& i : a) cin >> i;
  for (int i = 0; i < 10; i++) {
    stv[s[i]] = i;
    vts[i] = s[i];
  }
  if (bt(0, k)) {
    reverse(res.begin(), res.end());
    cout << res;
  } else {
    cout << -1;
  }
  return 0;
}
