#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
string t[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
int count_dig(string &s, int n) {
  int flag = 1, cnt = 0;
  for (int i = 0; i < 7; i++) {
    if (t[n][i] == s[i])
      continue;
    else if (t[n][i] == '1')
      cnt++;
    else {
      flag = 0;
      break;
    }
  }
  if (flag == 0)
    return -1;
  else
    return cnt;
}
int dp[2005][2005];
string s[2005];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, k;
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  reverse(s + 1, s + n + 1);
  for (int i = 0; i <= k; i++) {
    for (int d = 9; d >= 0; d--) {
      if (count_dig(s[1], d) == i) {
        dp[1][i] = d;
        break;
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      for (int d = 9; d >= 0; d--) {
        int cc = count_dig(s[i], d);
        if (cc > j || cc == -1) continue;
        if (dp[i - 1][j - cc] != -1) {
          dp[i][j] = d;
          break;
        }
      }
    }
  }
  string ans;
  int cur = k;
  for (int i = n; i >= 1; i--) {
    if (dp[i][cur] == -1) return cout << -1, 0;
    ans += (dp[i][cur] + '0');
    cur -= count_dig(s[i], dp[i][cur]);
  }
  cout << ans << '\n';
  return 0;
}
