#include <bits/stdc++.h>
using namespace std;
int n, k, dp[4005][4005];
string s[10] = {
    "1110111", "0010010", "1011101", "1011011", "0111010",
    "1101011", "1101111", "1010010", "1111111", "1111011",
};
string t[4005];
int mp[4005][10];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    for (int j = 0; j < 10; j++) {
      string a = t[i], b = s[j];
      int tot = 0;
      for (int l = 0; l < 7; l++) {
        if (a[l] == '0' && b[l] == '1')
          tot++;
        else if (a[l] == '1' && b[l] == '0')
          tot -= 10000;
      }
      mp[i][j] = tot;
    }
  }
  dp[n + 1][0] = 1;
  for (int i = n + 1; i > 1; i--) {
    for (int j = 0; j <= k; j++)
      if (dp[i][j]) {
        for (int l = 0; l < 10; l++)
          if (mp[i - 1][l] >= 0) dp[i - 1][j + mp[i - 1][l]] = 1;
      }
  }
  if (dp[1][k] != 1) {
    puts("-1");
    return 0;
  }
  int now = k;
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    int x;
    for (int j = 9; j >= 0; j--)
      if (mp[i][j] >= 0) {
        if (dp[i + 1][now - mp[i][j]]) {
          now -= mp[i][j];
          x = j;
          break;
        }
      }
    ans.push_back(x);
  }
  for (auto x : ans) cout << x;
  puts("");
}
