#include <bits/stdc++.h>
long long int power(long long int x, long long int b) {
  long long int p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= 1000000007;
    }
    b >>= 1;
    x *= x;
    x %= 1000000007;
  }
  return p % 1000000007;
}
using namespace std;
long long int dp[2001][2001];
long long int ans[2001];
long long int totals(string s) {
  long long int ans = 0;
  for (long long int i = 0; i < 7; i++) {
    if (s[i] == '1') ans++;
  }
  return ans;
}
long long int convston(string s) {
  if (s == "0010010") return 1;
  if (s == "1011101") return 2;
  if (s == "1011011") return 3;
  if (s == "0111010") return 4;
  if (s == "1110111") return 0;
  if (s == "1101011") return 5;
  if (s == "1101111") return 6;
  if (s == "1010010") return 7;
  if (s == "1111111") return 8;
  if (s == "1111011") return 9;
}
string ntos(long long int n) {
  if (n == 0) return "1110111";
  if (n == 1) return "0010010";
  if (n == 2) return "1011101";
  if (n == 3) return "1011011";
  if (n == 4) return "0111010";
  if (n == 5) return "1101011";
  if (n == 6) return "1101111";
  if (n == 7) return "1010010";
  if (n == 8) return "1111111";
  if (n == 9) return "1111011";
}
long long int atob(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;
}
bool rec(long long int ind, string arr[], long long int k, long long int n) {
  if (k < 0 && ind < n) return false;
  if (ind == n) {
    if (k == 0)
      return true;
    else
      return false;
  }
  if (dp[ind][k] != -1) return dp[ind][k];
  long long int temp = 0;
  for (long long int i = 9; i >= 0; i--) {
    temp = atob(arr[ind], ntos(i));
    if (temp != -1 && temp <= k) {
      bool f = rec(ind + 1, arr, k - temp, n);
      if (f) {
        ans[ind] = i;
        dp[ind][k] = 1;
        return true;
      }
    }
  }
  dp[ind][k] = 0;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    string arr[n];
    for (long long int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (long long int i = 0; i < n + 1; i++)
      for (long long int j = 0; j < k + 1; j++) dp[i][j] = -1;
    bool f = rec(0, arr, k, n);
    if (f) {
      for (long long int i = 0; i < n; i++) {
        cout << ans[i];
      }
      cout << "\n";
    } else {
      cout << -1 << "\n";
    }
  }
  return 0;
}
