#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
struct point {
  long long int x, y;
};
vector<string> num = {"1110111", "0010010", "1011101", "1011011", "0111010",
                      "1101011", "1101111", "1010010", "1111111", "1111011"};
long long int calc(string s1, string s2) {
  long long int ans = 0;
  for (long long int i = 0; i < 7; i++) {
    if (s1[i] == '1' && s2[i] == '0') {
      return -1;
    }
    if (s1[i] == '0' && s2[i] == '1') {
      ans++;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  vector<string> arr(n);
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int dp[k + 1][n];
  for (long long int i = 0; i < k + 1; i++) {
    for (long long int j = 0; j < n; j++) {
      dp[i][j] = 0;
    }
  }
  for (long long int i = 0; i < 10; i++) {
    long long int val = calc(arr[n - 1], num[i]);
    if (val != -1 && val <= k) dp[val][n - 1] = 1;
  }
  for (long long int i = n - 1 - 1; i >= 0; i--) {
    vector<long long int> v1;
    for (long long int z = 0; z < 10; z++) {
      long long int val = calc(arr[i], num[z]);
      if (val != -1) {
        v1.push_back(val);
      }
    }
    for (long long int j = 0; j < k + 1; j++) {
      if (dp[j][i + 1] == 1) {
        for (auto x : v1) {
          if (j + x <= k) {
            dp[j + x][i] = 1;
          }
        }
      }
    }
  }
  vector<long long int> ans(n, 0);
  long long int k2 = k;
  if (dp[k][0] != 1) {
    cout << "-1\n";
    return 0;
  }
  for (long long int i = 0; i < n - 1; i++) {
    for (long long int z = 10 - 1; z >= 0; z--) {
      long long int val = calc(arr[i], num[z]);
      if (val != -1 && k2 - val >= 0)
        if (dp[k2 - val][i + 1] == 1) {
          ans[i] = z;
          k2 -= val;
          break;
        }
    }
  }
  for (long long int z = 10 - 1; z >= 0; z--) {
    long long int val = calc(arr[n - 1], num[z]);
    if (val != -1)
      if (val == k2) {
        ans[n - 1] = z;
        break;
      }
  }
  for (auto x : ans) {
    cout << x;
  }
  cout << "\n";
}
