#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, z;
long long par[200000], sz[200000];
map<long long, long long> cntofsz;
vector<pair<long long, long long> > coins;
long long dp[200000];
bool isLucky(long long val) {
  while (val) {
    if (val % 10 != 4 && val % 10 != 7) return false;
    val = val / 10;
  }
  return true;
}
long long fndpar(long long pos) {
  if (par[pos] == pos) return pos;
  return par[pos] = fndpar(par[pos]);
}
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
  for (long long i = 1; i <= m; i++) {
    scanf("%lld %lld", &x, &y);
    x = fndpar(x);
    y = fndpar(y);
    if (x == y) continue;
    par[y] = x;
    sz[x] += sz[y];
  }
  for (long long i = 1; i <= n; i++) {
    if (fndpar(i) == i) {
      cntofsz[sz[i]]++;
    }
  }
  for (auto tmp : cntofsz) {
    long long val = tmp.first;
    long long cnt = tmp.second;
    long long cur = 1, xx = 0;
    while (xx + cur <= cnt) {
      coins.push_back({val * cur, cur});
      xx = xx + cur;
      cur = cur * 2;
    }
    if (cnt - xx > 0) coins.push_back({val * (cnt - xx), cnt - xx});
  }
  dp[0] = 0;
  for (long long i = 1; i <= n; i++) dp[i] = 1e17;
  if (coins.size() > 650) assert(false);
  for (long long i = 0; i < coins.size(); i++) {
    for (long long j = n; j >= 1; j--) {
      if (j - coins[i].first < 0) break;
      dp[j] = min(dp[j], dp[j - coins[i].first] + coins[i].second);
    }
  }
  long long ans = 1e17;
  for (long long i = 1; i <= n; i++) {
    if (isLucky(i) == false) continue;
    ans = min(ans, dp[i]);
  }
  if (ans > 1e16) ans = 0;
  cout << ans - 1 << endl;
  return 0;
}
