#include <bits/stdc++.h>
using namespace std;
string digit[2001];
string d;
string rep[10];
int nums[2000][10];
int n, k;
string extract[2020][2020];
void init() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      extract[i][j] = "*";
    }
  }
  d = "0123456789";
  rep[0] = "1110111";
  rep[1] = "0010010";
  rep[2] = "1011101";
  rep[3] = "1011011";
  rep[4] = "0111010";
  rep[5] = "1101011";
  rep[6] = "1101111";
  rep[7] = "1010010";
  rep[8] = "1111111";
  rep[9] = "1111011";
}
int XOR(int i, int j) {
  int ans = 0;
  for (int k = 0; k < 7; k++) {
    if (digit[i][k] == '0' && rep[j][k] == '1') {
      ans++;
    }
    if (digit[i][k] == '1' && rep[j][k] == '0') return -1;
  }
  return ans;
}
void calcnums() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      nums[i][j] = XOR(i, j);
    }
  }
}
string calcanswer(int i, int K) {
  if (K < 0) {
    return "-1";
  }
  if (i == n - 1 && K) {
    for (int k = 9; k >= 0; k--) {
      if (nums[i][k] == K) {
        string x = "";
        x += d[k];
        return x;
      }
    }
    return "-1";
  }
  if (extract[i][K] != "*") return extract[i][K];
  for (int j = 9; j >= 0; j--) {
    if (nums[i][j] != -1) {
      string temp = calcanswer(i + 1, K - nums[i][j]);
      if (temp != "-1") {
        string temp2 = "";
        temp2 += d[j];
        temp2 += temp;
        extract[i][K] = temp2;
        return extract[i][K];
      }
    }
  }
  extract[i][K] = "-1";
  return extract[i][K];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> digit[i];
  }
  init();
  calcnums();
  string answers = calcanswer(0, k);
  cout << answers << '\n';
}
