#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (y > x) x = y;
}
const long long int mod = (1000000007);
string num[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                  "1101011", "1101111", "1010010", "1111111", "1111011"};
int find(string a, string b) {
  int ans = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == '1' && b[i] == '0') return -1;
    if (a[i] != b[i]) ans++;
  }
  return ans;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  string a[n + 10];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int b[n + 10][k + 10], pos[n + 10][k + 10];
  ;
  for (int i = 0; i < n; i++) {
    for (int j = k; j >= 0; j--) {
      pos[i][j] = 0;
    }
  }
  pos[n - 1][0] = 1;
  long long int prev = k;
  for (int i = n - 2; i >= 0; i--) {
    long long int make[10], op = 0;
    for (int h = 0; h < 10; h++) {
      make[h] = find(a[i + 1], num[h]);
    }
    for (int j = k; j >= 0; j--) {
      if (b[i][j] == -1) continue;
      for (int h = 9; h >= 0; h--) {
        if (make[h] != -1 && j >= make[h] && pos[i + 1][j - make[h]] == 1) {
          pos[i][j] = 1;
          break;
        }
      }
    }
  }
  string ans = "";
  int high = k;
  for (int i = 0; i < n; i++) {
    long long int make[10], op = 0;
    for (int h = 9; h >= 0; h--) {
      make[h] = find(a[i], num[h]);
      if (make[h] != -1 && high - make[h] >= 0 && pos[i][high - make[h]] == 1) {
        high = high - make[h];
        ans.push_back(h + '0');
        op++;
        break;
      }
    }
    if (op == 0) {
      cout << "-1" << endl;
      return;
    }
  }
  cout << ans << endl;
}
int main() {
  clock_t tt;
  tt = clock();
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  tt = clock() - tt;
  double time_taken = ((double)tt) / CLOCKS_PER_SEC;
  return 0;
}
