#include <bits/stdc++.h>
using namespace std;
int n, m, dp[2020][2020], value[1010];
string a[2010];
int get(string &s) {
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      res = res + (1 << i);
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  string digits[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                     "1101011", "1101111", "1010010", "1111111", "1111011"};
  for (int i = 0; i <= 9; i++) {
    value[i] = get(digits[i]);
  }
  for (int i = 0; i <= n + 10; i++) {
    for (int j = 0; j <= m + 10; j++) {
      dp[i][j] = -1;
    }
  }
  dp[n + 1][m] = 0;
  for (int i = n; i >= 1; i--) {
    int temp = get(a[i]);
    for (int d = 0; d <= 9; d++) {
      int mask = temp | value[d];
      if (mask == value[d]) {
        int cnt = __builtin_popcount(temp ^ value[d]);
        for (int j = m; j >= 0; j--) {
          if (dp[i + 1][j + cnt] != -1) {
            dp[i][j] = max(dp[i][j], d);
          }
        }
      }
    }
  }
  if (dp[1][0] == -1) {
    cout << -1;
    return 0;
  }
  string ans;
  for (int i = 1, j = 0; i <= n; i++) {
    ans.push_back((char)(dp[i][j] + '0'));
    j = j + __builtin_popcount(get(a[i]) ^ value[dp[i][j]]);
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
  }
}
