#include <bits/stdc++.h>
using namespace std;
const int M = 2e3 + 7;
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int ex[300][10];
int dp[M][M];
bool ch[M][M];
int a[M];
string s;
int n, k;
void solve() {
  for (int i = 0; i < 256; i++) {
    for (int j = 0; j <= 9; j++) {
      int &co = ex[i][j];
      for (int k = 0; k < 7; k++) {
        if ((i & (1 << k)) == 0 && num[j][6 - k] == '1') co++;
        if ((i & (1 << k)) && num[j][6 - k] == '0') {
          co = -1;
          break;
        }
      }
    }
  }
  cin >> n >> k;
  ch[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    for (int j = 0; j <= 6; j++) a[i] = a[i] * 2 + s[j] - '0';
  }
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; ++j) {
      for (int t = 0; t <= 9; ++t)
        if (ex[a[i]][t] != -1 && j - ex[a[i]][t] >= 0) {
          if (ch[i - 1][j - ex[a[i]][t]]) {
            ch[i][j] = 1;
            dp[i][j] = t;
          }
        }
    }
  }
  if (!ch[n][k]) {
    cout << -1;
    return;
  }
  for (int i = n; i >= 1; --i) {
    cout << dp[i][k];
    k -= ex[a[i]][dp[i][k]];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
