#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAXN = 2e5 + 10;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long INF = 8e18;
const int LOG = 22;
long long pw(long long a, long long b, long long mod) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod
                      : pw(a * a % mod, b / 2, mod)));
}
int sz[MAXN], par[MAXN];
long long dp[MAXN], T[MAXN];
int GET(int x) { return ((x == par[x]) ? x : par[x] = GET(par[x])); }
void unify(int v, int u) {
  v = GET(v), u = GET(u);
  if (v == u) return;
  if (sz[u] > sz[v]) {
    swap(u, v);
  }
  par[u] = v;
  sz[v] += sz[u];
}
bool is_OK(int x) {
  while (x) {
    int last = x % 10;
    if (last != 4 && last != 7) {
      return 0;
    }
    x /= 10;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    sz[i] = 1;
    par[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    unify(a, b);
  }
  for (int i = 1; i <= n; i++) {
    if (GET(i) == i) {
      T[sz[i]]++;
    }
  }
  vector<pair<long long, long long> > coins;
  int mid = MAXN - 1;
  for (int i = 1; i <= mid; i++) {
    long long z = 1;
    while (T[i]) {
      long long Mn = min(T[i], z);
      coins.push_back(make_pair(Mn, Mn * i));
      T[i] -= Mn;
      z *= 2;
    }
  }
  for (int i = 1; i < MAXN; i++) {
    dp[i] = 1e18;
  }
  for (auto x : coins) {
    for (int i = MAXN - 1; i >= x.second; i--) {
      dp[i] = min(dp[i], dp[i - x.second] + x.first);
    }
  }
  long long ans = 1e18;
  for (int i = 1; i < MAXN; i++) {
    if (is_OK(i)) {
      ans = min(ans, dp[i]);
    }
  }
  if (ans == 1e18) {
    ans = 0;
  }
  cout << ans - 1;
  return 0;
}
