#include <bits/stdc++.h>
using namespace std;
int N, K;
pair<int, int> dp[2001][2001];
int costs[2001][10];
string digs[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  for (int i = (0); i < (N); i++) {
    string str;
    cin >> str;
    for (int d = (0); d < (10); d++) {
      int cost = 0;
      for (int j = (0); j < (7); j++) {
        if (str[j] == '1' && digs[d][j] == '0') {
          cost = -1;
          break;
        }
        if (str[j] == '0' && digs[d][j] == '1') cost++;
      }
      costs[N - i][d] = cost;
    }
  }
  for (int i = (0); i < (N + 1); i++)
    for (int j = (0); j < (K + 1); j++) dp[i][j].first = -1;
  dp[0][0].first = 1;
  for (int i = (1); i < (N + 1); i++) {
    for (int j = (0); j < (K + 1); j++) {
      for (int k = (0); k < (10); k++) {
        if (costs[i][k] <= j && costs[i][k] != -1 &&
            dp[i - 1][j - costs[i][k]].first != -1) {
          dp[i][j].first = k;
          dp[i][j].second = j - costs[i][k];
        }
      }
    }
  }
  if (dp[N][K].first == -1) {
    cout << -1 << '\n';
  } else {
    int ind = K;
    for (int i = (N + 1 - 1); i >= 1; i--) {
      cout << dp[i][ind].first;
      ind = dp[i][ind].second;
    }
    cout << '\n';
  }
}
