#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int n, k, dp[N][N], cost[N][10];
vector<string> g;
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int go(int i, int rem) {
  if (i == n) return dp[i][rem] = rem == 0;
  int &ret = dp[i][rem];
  if (ret != -1) return ret;
  ret = 0;
  for (int d = 9; d >= 0; --d) {
    if (cost[i][d] <= rem) ret |= go(i + 1, rem - cost[i][d]);
  }
  return ret;
}
void print(int i, int rem) {
  if (i == n) return;
  for (int d = 9; d >= 0; --d) {
    if (cost[i][d] <= rem and go(i + 1, rem - cost[i][d])) {
      cout << d;
      print(i + 1, rem - cost[i][d]);
      return;
    }
  }
}
void solve() {
  cin >> n >> k;
  g.resize(n);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; ++i) cin >> g[i];
  for (int i = 0; i < n; ++i) {
    for (int d = 0; d <= 9; ++d) {
      int c = 0;
      bool can = true;
      for (int j = 0; j < 7; ++j) {
        if (g[i][j] > num[d][j]) can = false;
        c += num[d][j] > g[i][j];
      }
      cost[i][d] = can ? c : 1e9;
    }
  }
  if (go(0, k)) {
    print(0, k);
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
