#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 50;
const int maxm = 25 + 1;
const long long inf = 1e18;
int dp[maxn][maxn];
string dig[maxn];
int n, k;
pair<int, int> pre[maxn][maxn];
string num[10] = {
    string("1110111"), string("0010010"), string("1011101"), string("1011011"),
    string("0111010"), string("1101011"), string("1101111"), string("1010010"),
    string("1111111"), string("1111011"),
};
inline void solve() {
  dp[n + 1][k] = 10;
  for (int i = (n); i >= (1); --i) {
    for (int j = (0); j <= (k); ++j) {
      for (int m = (9); m >= (0); --m) {
        int nd, rl, ok;
        nd = rl = 0;
        ok = 1;
        for (int p = (0); p < (7); ++p) {
          if (num[m][p] == '1' && dig[i][p] == '1') {
          }
          if (num[m][p] == '1' && dig[i][p] == '0') {
            nd++;
          }
          if (num[m][p] == '0' && dig[i][p] == '1') {
            ok = 0;
          }
          if (num[m][p] == '0' && dig[i][p] == '0') {
          }
        }
        if (ok) {
          for (int p = (nd); p <= (nd); ++p) {
            if (dp[i + 1][j + p] != -1) {
              pair<int, int> e = pre[i][j];
              if (dp[i][j] == -1) {
                dp[i][j] = m;
                pre[i][j].first = i + 1;
                pre[i][j].second = j + p;
                e = pre[i][j];
              }
            }
          }
        }
      }
    }
  }
  if (dp[1][0] == -1) {
    cout << "-1\n";
    return;
  }
  string ans;
  pair<int, int> now = (pair<int, int>){1, 0};
  while (now.first <= n) {
    assert(dp[now.first][now.second] != -1);
    ans.push_back(dp[now.first][now.second] + '0');
    auto e = pre[now.first][now.second];
    now = e;
  }
  cout << ans << endl;
}
int main(void) {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  ;
  cin >> n >> k;
  for (int i = (1); i <= (n); ++i) {
    cin >> dig[i];
  }
  memset(dp, -1, sizeof(dp));
  solve();
  return 0;
}
