#include <bits/stdc++.h>
using namespace std;
const long long MAX1 = 2e3 + 300, MOD = 1e9 + 7;
int n, k, dp[MAX1][MAX1];
string s[MAX1], t[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
int super(string s1, string s2) {
  int jav = 0;
  for (int i = 0; i < 7; ++i) {
    if (s1[i] == '1' && s2[i] != '1')
      return 9;
    else if (s1[i] == '0' && s2[i] == '1')
      ++jav;
  }
  return jav + 10;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  dp[n][k] = 1;
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j <= k; ++j) {
      if (dp[i][j] != 1) continue;
      for (int l = 0; l < 10; ++l) {
        int x = super(s[i], t[l]) - 10;
        if (x != -1 && j - x >= 0) dp[i - 1][j - x] = 1;
      }
    }
  }
  if (!dp[0][0]) {
    cout << -1;
    return 0;
  }
  long long cnt = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 9; j >= 0; --j) {
      int x = super(s[i], t[j]) - 10;
      if (x != -1 && dp[i][x + cnt]) {
        cout << j;
        cnt += x;
        break;
      }
    }
  }
  return 0;
}
