#include <bits/stdc++.h>
using namespace std;
int cnt[2005][10];
vector<string> digit = {"1110111", "0010010", "1011101", "1011011", "0111010",
                        "1101011", "1101111", "1010010", "1111111", "1111011"};
string dp[2005][2005];
string memoize(vector<string> &s, int i, int k) {
  if (i == s.size()) {
    if (k != 0) return "-1";
    return dp[i][k];
  }
  if (dp[i][k] != "") return dp[i][k];
  for (int j = 9; j >= 0; j--) {
    if (cnt[i][j] <= k) {
      string m = memoize(s, i + 1, k - cnt[i][j]);
      if (m != "-1") {
        dp[i][k] = m + char(j + '0');
        break;
      }
    }
  }
  if (dp[i][k] == "") dp[i][k] = "-1";
  return dp[i][k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++) {
    string s1 = s[i];
    for (int j = 0; j < 10; j++) {
      string s2 = digit[j];
      for (int k = 0; k < 7; k++) {
        if (s1[k] == '1' and s2[k] == '0') {
          cnt[i][j] = INT_MAX;
          break;
        } else if (s1[k] == '0' and s2[k] == '1')
          cnt[i][j]++;
      }
    }
  }
  string ans = memoize(s, 0, m);
  if (ans == "-1")
    cout << "-1";
  else {
    for (int i = ans.length() - 1; i >= 0; i--) cout << ans[i];
  }
  return 0;
}
