#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int n, k;
string s[2001];
string nums[10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
int dp[2001][2001];
long long int ans[2001];
long long int check(string a, string b) {
  long long int ans = 0;
  for (long long int i = 0; i < 7; i++) {
    if (b[i] == '0' && a[i] == '1') {
      return -1;
    } else if (b[i] == '1' && a[i] == '0') {
      ans++;
    }
  }
  return ans;
}
int fun(long long int i, long long int j) {
  if (i == n && j == 0) {
    dp[n][j] = 1;
    return 1;
  } else if (i == n || j < 0) {
    return 0;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  int tmp = 0;
  for (long long int k = 9; k >= 0; k--) {
    long long int z = check(s[i], nums[k]);
    if (z <= j && z != -1) {
      tmp = fun(i + 1, j - z);
      if (tmp == 1) {
        ans[i] = k;
        dp[i][j] = tmp;
        break;
      }
    }
  }
  return dp[i][j] = tmp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    cin >> n >> k;
    for (long long int i = 0; i < n; i++) {
      cin >> s[i];
    }
    memset(dp, -1, sizeof(dp));
    long long int a = fun(0, k);
    if (a == 0) {
      cout << -1;
    } else {
      for (long long int i = 0; i < n; i++) {
        cout << ans[i];
      }
    }
  }
  return 0;
}
