#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
const int N = 2005;
string s[N], t[10];
int a[N], dp[N][N], n, k, pos[N][10];
int rec(int in, int rem) {
  if (in >= n) return rem == 0;
  if (dp[in][rem] != -1) return dp[in][rem];
  if (rem < 0) return 0;
  for (int j = 9; j >= 0; j--) {
    int c = pos[in][j];
    if (c == -1 || c > rem) continue;
    if (rec(in + 1, rem - c)) {
      a[in] = j;
      return dp[in][rem] = 1;
    }
  }
  return dp[in][rem] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  t[0] = "1110111", t[1] = "0010010", t[2] = "1011101", t[3] = "1011011",
  t[4] = "0111010", t[5] = "1101011", t[6] = "1101111", t[7] = "1010010",
  t[8] = "1111111", t[9] = "1111011";
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int k = 0; k < n; k++) {
    for (int j = 9; j >= 0; j--) {
      int c = 0;
      for (int i = 0; i < 7; i++) {
        if (s[k][i] == '1' && t[j][i] == '0') {
          c = -1;
          break;
        }
        if (s[k][i] == '0' && t[j][i] == '1') c++;
      }
      pos[k][j] = c;
    }
  }
  memset(dp, -1, sizeof(dp));
  if (rec(0, k) == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) cout << a[i];
  return 0;
}
