#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9;
const int N = 3e5 + 5;
int arr[2005][10], n;
string dp[2005][2005];
string numbers[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                      "1101011", "1101111", "1010010", "1111111", "1111011"};
int getDiff(string s, string num) {
  int cnt = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == '1' && num[i] != '1') return -1;
    cnt += (s[i] == '0' && num[i] == '1');
  }
  return cnt;
}
string solve(int idx, int rem) {
  if (idx == n) {
    return (rem == 0) ? "" : "-1";
  }
  if (rem < 0) return "-1";
  if (!dp[idx][rem].empty()) return dp[idx][rem];
  string ans = "-1";
  for (int i = 9; i >= 0; i--) {
    if (arr[idx][i] == -1) continue;
    string val = solve(idx + 1, rem - arr[idx][i]);
    if (val == "-1") continue;
    val = char('0' + i) + val;
    ans = val;
    break;
  }
  return dp[idx][rem] = ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < 10; j++) {
      arr[i][j] = getDiff(s, numbers[j]);
    }
  }
  memset(dp, 0, sizeof(dp));
  cout << solve(0, k) << endl;
}
