#include <bits/stdc++.h>
using namespace std;
void data() {}
const int N = 1e6 + 100;
const long long mod = 998244353;
const long long mod2 = 1e9 + 7;
int cost[2005][110];
int dp[2105][2105];
string c[11] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
int main() {
  data();
  int n, k;
  cin >> n >> k;
  string s[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 10; j++) {
      int cur = 0;
      for (int k2 = 0; k2 < s[i].size(); k2++) {
        if (s[i][k2] != c[j][k2] && s[i][k2] == '1') {
          cur = -1;
          break;
        } else if (s[i][k2] != c[j][k2]) {
          cur++;
        }
      }
      cost[i][j] = cur;
    }
  }
  dp[n + 1][0] = 1;
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j <= k; j++) {
      if (dp[i + 1][j]) {
        for (int k2 = 0; k2 < 10; k2++) {
          if (cost[i][k2] != -1) {
            dp[i][j + cost[i][k2]] = 1;
          }
        }
      }
    }
  }
  if (dp[1][k] != 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 9; j >= 0; --j) {
      if (cost[i][j] != -1 && dp[i + 1][k - cost[i][j]] && k >= cost[i][j]) {
        cout << j;
        k -= cost[i][j];
        break;
      }
    }
  }
}
