#include <bits/stdc++.h>
using namespace std;
const int N = 3077;
int n, m, k, t;
int a[N];
int p[N];
int pos[N];
int step[N];
int st[N];
int dp[N][14];
int nxt[N][N];
int inf = 1e9;
int ans[N][N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  step[0] = 1;
  for (int j = 1; j <= 10; j++) {
    step[j] = step[j - 1] * 2;
  }
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int sum = 0;
    for (int j = 0; j < 7; j++) {
      int x = s[j] - ('0');
      sum = sum + x * step[j];
    }
    a[i] = sum;
  }
  for (int i = 0; i <= 128; i++) {
    for (int j = 0; j <= 9; j++) {
      dp[i][j] = inf;
    }
  }
  dp[119][0] = 0;
  dp[36][1] = 0;
  dp[93][2] = 0;
  dp[109][3] = 0;
  dp[127][8] = 0;
  dp[46][4] = 0;
  dp[107][5] = 0;
  dp[123][6] = 0;
  dp[37][7] = 0;
  dp[111][9] = 0;
  for (int i = (1 << 7) - 1; i >= 0; i--) {
    for (int j = 0; j <= 6; j++) {
      int x = step[j] ^ i;
      if (x > i) {
        for (int t = 0; t <= 9; t++) {
          dp[i][t] = min(dp[i][t], dp[x][t] + 1);
        }
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j <= k; j++) {
      nxt[i][j] = -1;
    }
  }
  for (int i = 0; i <= 9; i++) {
    int x = a[n];
    if (dp[x][i] == inf) {
      continue;
    }
    nxt[n][dp[x][i]] = 0;
    ans[n][dp[x][i]] = i;
  }
  for (int i = n - 1; i >= 1; i--) {
    for (int num = 0; num <= 9; num++) {
      for (int j = 0; j <= k; j++) {
        int x = a[i];
        if (dp[x][num] == inf || nxt[i + 1][j] == -1) {
          continue;
        }
        ans[i][j + dp[x][num]] = num;
        nxt[i][j + dp[x][num]] = j;
      }
    }
  }
  if (nxt[1][k] == -1) {
    cout << -1 << "\n";
    return 0;
  }
  int cur = k;
  for (int i = 1; i <= n; i++) {
    cout << ans[i][cur];
    cur = nxt[i][cur];
  }
  return 0;
}
