#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long n, m, k, t;
vector<int> G[2005];
string s[2005];
int dp[2005][2005];
int v[200][20];
int mp[200][20];
string p[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
              "1101011", "1101111", "1010010", "1111111", "1111011"};
int a[2005][2005];
int con(string a, int b) {
  int num = 0;
  for (int i = 0; i < 7; i++) {
    if (a[i] == '0' && p[b][i] == '1') num++;
    if (a[i] == '1' && p[b][i] == '0') return -1;
  }
  return num;
}
int d[2005];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < 128; i++) {
    string np;
    for (int j = 0; j < 7; j++) {
      if ((i >> j) & 1) {
        np.append("1");
      } else {
        np.append("0");
      }
    }
    for (int j = 0; j < 10; j++) {
      mp[i][j] = con(np, j);
    }
  }
  for (int i = 0; i < n / 2; i++) {
    swap(s[i], s[n - i - 1]);
  }
  for (int i = 0; i < n; i++) {
    d[i] = 0;
    for (int j = 0; j < 7; j++) {
      if (s[i][j] == '1') d[i] |= (1 << j);
    }
  }
  memset(a, -1, sizeof(a));
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  a[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      for (int p = 0; p < 10; p++) {
        if (dp[i][j] == -1) continue;
        if (mp[d[i]][p] == -1) continue;
        if (j + mp[d[i]][p] > k) continue;
        if (p > a[i + 1][j + mp[d[i]][p]]) {
          a[i + 1][j + mp[d[i]][p]] = p;
          dp[i + 1][j + mp[d[i]][p]] = j;
        }
      }
    }
  }
  if (a[n][k] == -1) {
    cout << "-1";
    return 0;
  }
  int j = k;
  for (int i = n; i >= 1; i--) {
    cout << a[i][j];
    j = dp[i][j];
  }
}
