#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long INF = 8e18;
const int maxn = 2e3 + 5;
vector<int> num[maxn];
string s[10], b[maxn];
int n, k;
int a[10], fa[10];
int dp[maxn][maxn];
inline void init() {
  s[0] = "1110111", s[1] = "0010010", s[2] = "1011101", s[3] = "1011011",
  s[4] = "0111010", s[5] = "1101011", s[6] = "1101111", s[7] = "1010010",
  s[8] = "1111111", s[9] = "1111011";
  a[0] = 6, a[1] = 2, a[2] = 5, a[3] = 5, a[4] = 4, a[5] = 5, a[6] = 6,
  a[7] = 3, a[8] = 7, a[9] = 6;
  for (int i = 0; i < 10; ++i) fa[a[i]] = i;
  for (int i = 9; i >= 0; --i) {
    int S = 0;
    for (auto x : s[i]) {
      S <<= 1;
      S += x - '0';
    }
    for (int s1 = S; s1 != 0; s1 = (s1 - 1) & S) num[s1].push_back(i);
    num[0].push_back(i);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> b[i];
  dp[n + 1][k] = 1;
  for (int i = n; i >= 1; --i) {
    string x = b[i];
    int S = 0, cnt = 0;
    for (auto y : x) {
      S <<= 1;
      S += y - '0';
      if (y - '0' == 1) ++cnt;
    }
    for (auto y : num[S]) {
      int val = a[y] - cnt;
      for (int j = 0; j + val <= k; ++j) {
        if (dp[i + 1][j + val]) dp[i][j] = 1;
      }
    }
  }
  if (!dp[1][0]) {
    cout << -1 << '\n';
    return 0;
  }
  int last = 0;
  vector<int> ans;
  for (int i = 1; i <= n; ++i) {
    string x = b[i];
    int S = 0, cnt = 0;
    for (auto y : x) {
      S <<= 1;
      S += y - '0';
      if (y - '0' == 1) ++cnt;
    }
    for (auto y : num[S]) {
      int val = a[y] - cnt;
      if (dp[i + 1][last + val]) {
        ans.push_back(y);
        last = last + val;
        break;
      }
    }
  }
  for (auto x : ans) cout << x;
  return 0;
}
