#include <bits/stdc++.h>
using namespace std;
const long long mxn = 5e5 + 5;
long long a[mxn];
long long b[mxn];
bitset<7> bs[2005];
bitset<7> st[10];
long long cost[2005][20];
long long dp[2005][2005];
void dfs(long long n, long long k) {
  if (n == 1)
    cout << dp[n][k];
  else {
    cout << dp[n][k];
    dfs(n - 1, k - cost[n][dp[n][k]]);
  }
  return;
}
signed main(void) {
  long long n, k;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  bitset<7> b0("1110111");
  bitset<7> b1("0010010");
  bitset<7> b2("1011101");
  bitset<7> b3("1011011");
  bitset<7> b4("0111010");
  bitset<7> b5("1101011");
  bitset<7> b6("1101111");
  bitset<7> b7("1010010");
  bitset<7> b8("1111111");
  bitset<7> b9("1111011");
  st[0] = b0, st[1] = b1, st[2] = b2, st[3] = b3, st[4] = b4, st[5] = b5,
  st[6] = b6, st[7] = b7, st[8] = b8, st[9] = b9;
  for (long long i = 1; i <= n; i++) {
    string s;
    cin >> s;
    bitset<7> tmp(s);
    bs[i] = tmp;
  }
  reverse(bs + 1, bs + n + 1);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < 10; j++) {
      long long cnt = 0;
      for (long long m = 0; m < 7; m++) {
        if (bs[i][m] == 1 && st[j][m] == 0) {
          cnt = 99999999;
          break;
        } else {
          cnt += (bs[i][m] == st[j][m] ? 0 : 1);
        }
      }
      cost[i][j] = cnt;
    }
  }
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= k; j++) {
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= k; j++) {
      for (long long m = 0; m < 10; m++) {
        if (j >= cost[i][m] && dp[i - 1][j - cost[i][m]] != -1) dp[i][j] = m;
      }
    }
  }
  if (dp[n][k] != -1)
    dfs(n, k);
  else {
    cout << -1 << endl;
  }
  return 0;
}
