#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int a[10] = {119, 36, 93, 109, 46, 107, 123, 37, 127, 111};
int s[N];
int dp[200][10];
int solve(int x) {
  for (int i = 0; i < 10; i++) {
    if (a[i] == x) return i;
  }
  return -1;
}
int yuan;
void dfs(int x, int y, int bj) {
  dp[yuan][y] = max(dp[yuan][y], solve(x));
  if (y > 7) return;
  if (bj > 6) return;
  if (((1 << bj) & x) == 0) {
    dfs(x + (1 << bj), y + 1, bj + 1);
  }
  dfs(x, y, bj + 1);
}
int flag[N][N];
int get(int i, int j) {
  for (int x = 0; x <= 7; x++) {
    if (j - x >= 0 && dp[s[i]][x] != -1 && flag[i + 1][j - x]) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < (1 << 7); i++) {
    yuan = i;
    dfs(i, 0, 0);
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    string x;
    cin >> x;
    int ans = 0;
    for (int j = 0; j < 7; j++) {
      if (x[j] == '1') ans += (1 << j);
    }
    s[i] = ans;
  }
  flag[n + 1][0] = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j <= k; j++) {
      flag[i][j] = get(i, j);
    }
  }
  if (flag[1][k] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int ma = 0, p = 0;
    for (int j = 0; j <= 7; j++) {
      if (dp[s[i]][j] != -1 && k >= j && flag[i + 1][k - j]) {
        if (ma <= dp[s[i]][j]) {
          ma = dp[s[i]][j];
          p = j;
        }
      }
    }
    k -= p;
    cout << ma;
  }
  return 0;
}
