#include <bits/stdc++.h>
using namespace std;
long long int pwr(long long int base, long long int p) {
  long long int ans = 1;
  while (p) {
    if (p & 1) ans = ((ans % 1000000007) * (base % 1000000007)) % 1000000007;
    base = ((base % 1000000007) * (base % 1000000007)) % 1000000007;
    p /= 2;
  }
  return ans;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int powr(long long int base, long long int p) {
  long long int ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base);
    base = (base * base);
    p /= 2;
  }
  return ans;
}
long long int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
long long int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
long long int n, k;
string s[2002];
long long int dp[2002][2002];
vector<string> digits = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
long long int req[2002][12];
long long int ans[2002];
bool solve(long long int i, long long int j) {
  if (j > k) return false;
  if (i == n) {
    return (j == k);
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  for (long long int dig = 9; dig >= 0; dig--) {
    if (solve(i + 1, j + req[i][dig])) {
      ans[i] = dig;
      dp[i][j] = 1;
      return true;
    }
  }
  dp[i][j] = 0;
  return false;
}
long long int ones_req(long long int x, long long int y) {
  long long int c = 0;
  for (long long int i = (0); i < (8); ++i) {
    if (s[x][i] != digits[y][i]) {
      if (digits[y][i] == '0')
        return 3000;
      else
        c++;
    }
  }
  return c;
}
int32_t main() {
  scanf("%lld", &n);
  scanf("%lld", &k);
  for (long long int i = (0); i < (n); ++i) {
    cin >> s[i];
    for (long long int j = (0); j < (10); ++j) {
      req[i][j] = ones_req(i, j);
    }
  }
  memset(ans, -1, sizeof(ans));
  memset(dp, -1, sizeof(dp));
  solve(0, 0);
  long long int flag = 0;
  for (long long int i = (0); i < (n); ++i) {
    if (ans[i] == -1) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    cout << -1 << endl;
  } else {
    for (long long int i = (0); i < (n); ++i) cout << ans[i];
  }
}
