#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
void err() { cout << "\033[39;0m" << endl; }
template <class T, class... Ts>
void err(const T &arg, const Ts &...args) {
  cout << arg << " ";
  err(args...);
}
const int N = 2000 + 5;
int cost[N][10];
int n, k, a[N], ones[N];
int d[N][N], pre[N][N];
string tar;
unordered_map<string, int> mp;
string s[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
int calc(string &t, string &s) {
  int res = 0;
  for (int i = 0; i < 7; i++) {
    if (t[i] == '0' && s[i] == '1')
      res++;
    else if (t[i] != s[i])
      return -1;
  }
  return res;
}
void dfs(int x, int k) {
  int num = pre[x][k];
  tar += char('0' + num);
  if (x != 1) dfs(x - 1, k - cost[x][num]);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    string t;
    cin >> t;
    for (int j = 0; j < 10; j++) cost[n - i + 1][j] = calc(t, s[j]);
  }
  d[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 9; j++) {
      if (cost[i][j] == -1) continue;
      for (int l = k; l >= cost[i][j]; l--) {
        if (d[i - 1][l - cost[i][j]]) {
          d[i][l] = 1;
          pre[i][l] = j;
        }
      }
    }
  }
  if (!d[n][k]) {
    puts("-1");
  } else {
    tar = "";
    dfs(n, k);
    cout << tar << endl;
  }
  return 0;
}
