#include <bits/stdc++.h>
using namespace std;
void ip() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
string s[2005];
int n, k;
int C[2005][10];
int dp[2005][2005];
string dig[10];
int tr(string s, int d) {
  int diff = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == dig[d][i]) continue;
    if (s[i] == '1') {
      return 2005;
    } else if (s[i] == '0') {
      diff++;
    }
  }
  return diff;
}
int f(int pos, int k) {
  if (pos == n) {
    if (k == 0) return 1;
    return 0;
  }
  int &ans = dp[pos][k];
  if (ans != -1) return ans;
  ans = 0;
  for (int i = 0; i < 10; i++) {
    if (C[pos][i] <= k) {
      ans |= f(pos + 1, k - C[pos][i]);
    }
  }
  return ans;
}
void dfs(int pos, int k) {
  if (pos == n) {
    if (k == 0) {
      cout << endl;
      exit(0);
    }
    assert(1 == 2);
  }
  for (int i = 9; i >= 0; i--) {
    if (C[pos][i] <= k && f(pos + 1, k - C[pos][i])) {
      cout << i;
      dfs(pos + 1, k - C[pos][i]);
      assert(1 == 2);
    }
  }
}
int main() {
  dig[0] = "1110111";
  dig[1] = "0010010";
  dig[2] = "1011101";
  dig[3] = "1011011";
  dig[4] = "0111010";
  dig[5] = "1101011";
  dig[6] = "1101111";
  dig[7] = "1010010";
  dig[8] = "1111111";
  dig[9] = "1111011";
  memset(dp, -1, sizeof(dp));
  ip();
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < 10; j++) C[i][j] = tr(s[i], j);
  }
  if (f(0, k) == 0)
    cout << -1 << endl;
  else
    dfs(0, k);
  return 0;
}
