#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5, mod = 1e9 + 7, bit = 61;
vector<pair<char, int>> adj[N];
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int dp[N][N];
string mov = "";
string s[N];
int n, k;
int solve(int x, int rem) {
  if (x == n + 1) {
    return rem == 0;
  }
  if (rem < 0) {
    return 0;
  }
  int &ans = dp[x][rem];
  if (ans != -1) {
    return ans;
  }
  ans = 0;
  for (auto v : adj[x]) {
    int id = v.first - '0';
    int pen = v.second;
    if (solve(x + 1, rem - pen)) {
      ans = 1;
      break;
    }
  }
  return ans;
}
void path(int x, int rem) {
  if (x == n + 1) {
    return;
  }
  for (auto v : adj[x]) {
    int id = v.first - '0';
    int pen = v.second;
    if (solve(x + 1, rem - pen)) {
      mov += v.first;
      return path(x + 1, rem - pen);
    }
  }
  return;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      cin >> s[i];
      for (char ch = '0'; ch <= '9'; ch++) {
        bool pos = 1;
        int c = 0;
        int id = ch - '0';
        for (int j = 0; j <= 6; j++) {
          if (s[i][j] == '1' and num[id][j] != '1') {
            pos = 0;
            break;
          } else if (s[i][j] == '0' and num[id][j] == '1') {
            c++;
          }
        }
        if (pos) {
          adj[i].push_back({ch, c});
        }
      }
      reverse(adj[i].begin(), adj[i].end());
    }
    memset(dp, -1, sizeof(dp));
    if (solve(1, k)) {
      path(1, k);
      cout << mov << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
  return 0;
}
