#include <bits/stdc++.h>
using namespace std;
vector<string> look = {"1110111", "0010010", "1011101", "1011011", "0111010",
                       "1101011", "1101111", "1010010", "1111111", "1111011"};
int d(string a, int t) {
  int ans = 0;
  for (int i = 0; i < 7; i++) {
    if (look[t][i] == '0' and a[i] == '1') return -1;
    ans += look[t][i] == '1' and a[i] == '0';
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<string> arr(n);
  for (string &s : arr) cin >> s;
  vector<vector<int>> dp(n + 1, vector<int>(k + 1));
  dp[n][0] = 1;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j <= k; j++) {
      for (int t = 0; t < 10; t++) {
        int can = d(arr[i], t);
        if (can != -1 and can <= j) dp[i][j] |= dp[i + 1][j - can];
      }
    }
  }
  int ok = dp[0][k];
  if (!ok) return cout << -1 << "\n", 0;
  for (int i = 0; i < n; i++) {
    for (int t = 9; t >= 0; t--) {
      int can = d(arr[i], t);
      if (can == -1 or can > k) continue;
      if (dp[i + 1][k - can]) {
        cout << t;
        k -= can;
        break;
      }
    }
  }
  cout << "\n";
}
