#include <bits/stdc++.h>
using namespace std;
string digits[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"};
int d[10];
int n, k;
vector<int> v;
const int maxn = 2005, maxk = 2005;
int dp[maxn][maxk];
int go[maxn][10];
int proc(int sub, int sup) {
  if ((sub & sup) == sub) {
    return __builtin_popcount(sup - sub);
  }
  return -1;
}
int conv(string &s) {
  int ans = 0;
  for (char c : s) {
    ans *= 2;
    ans += (c - '0');
  }
  return ans;
}
int can(int i, int j) {
  if (i == n) return j == 0 ? 1 : 0;
  if (j < 0) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int ans = 0;
  for (int k = 9; k >= 0; --k) {
    if (go[i][k] != -1 && can(i + 1, j - go[i][k])) {
      ans = 1;
      break;
    }
  }
  return dp[i][j] = ans;
}
string sans;
void solve(int i, int j) {
  if (i == n) return;
  for (int k = 9; k >= 0; --k) {
    if (go[i][k] != -1 && can(i + 1, j - go[i][k])) {
      sans.push_back('0' + k);
      solve(i + 1, j - go[i][k]);
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (int i = 0; i < (10); ++i) {
    d[i] = conv(digits[i]);
  }
  cin >> n >> k;
  v.resize(n);
  string s;
  for (int i = 0; i < (n); ++i) {
    cin >> s;
    v[i] = conv(s);
  }
  memset(go, -1, sizeof(go));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (10); ++j) {
      go[i][j] = proc(v[i], d[j]);
    }
  }
  int ans = can(0, k);
  if (ans == 0) {
    cout << -1 << endl;
    return 0;
  }
  solve(0, k);
  cout << sans << endl;
}
