#include <bits/stdc++.h>
using namespace std;
vector<string> cor({"1110111", "0010010", "1011101", "1011011", "0111010",
                    "1101011", "1101111", "1010010", "1111111", "1111011"});
int dp[2002][2002];
string ans;
int n, k;
vector<string> have;
int can(string s, int v) {
  int ret = 0;
  for (int i = 0; i < 7; ++i) {
    if (cor[v][i] < s[i]) return -1;
    if (cor[v][i] > s[i]) ret++;
  }
  return ret;
}
bool solve(int lvl, int left) {
  if (lvl == n) {
    return (left == 0);
  }
  if (left < 0 || dp[lvl][left]) {
    return false;
  }
  for (int i = 9; i >= 0; --i) {
    int c = can(have[lvl], i);
    if (c == -1) continue;
    if (solve(lvl + 1, left - c)) {
      ans += (char)(i + '0');
      dp[lvl][left] = 2;
      return true;
    }
  }
  dp[lvl][left] = 1;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  have.resize(n);
  for (auto& x : have) {
    cin >> x;
  }
  if (solve(0, k)) {
    reverse(ans.begin(), ans.end());
    cout << ans;
  } else {
    cout << -1;
  }
}
