#include <bits/stdc++.h>
using namespace std;
int ufdata[100020];
void uf_init() { memset((ufdata), (-1), sizeof(ufdata)); }
int uf_root(int x) {
  return ufdata[x] < 0 ? x : ufdata[x] = uf_root(ufdata[x]);
}
bool uf_find(int x, int y) { return uf_root(x) == uf_root(y); }
void uf_union(int x, int y) {
  x = uf_root(x);
  y = uf_root(y);
  if (x != y) {
    if (ufdata[x] < ufdata[y]) swap(x, y);
    ufdata[x] += ufdata[y];
    ufdata[y] = x;
  }
}
int freq[100020], dp[100020];
int vi[100020], mm1[100020], mm2[100020];
void solve(int K, int num) {
  for (int i = 0; i < (int)(K); ++i) vi[i] += (K - i);
  for (int i = 0; i < (int)(K); ++i)
    mm1[i] = (i % num == 0) ? vi[i] : min(mm1[i - 1], vi[i]);
  for (int i = K - 1; i >= 0; i--)
    mm2[i] = ((i + 1) % num == 0) ? vi[i] : min(mm2[i + 1], vi[i]);
  for (int i = 0; i < (int)(K); ++i) {
    vi[i] = mm1[i];
    if (i - num + 1 >= 0) vi[i] = min(mm1[i], mm2[i - num + 1]);
    vi[i] -= (K - i);
  }
}
bool is_lucky(int n) {
  if (n == 0) return true;
  if (n % 10 != 7 && n % 10 != 4) return false;
  return is_lucky(n / 10);
}
int main() {
  int N, M;
  while (scanf("%d%d", &N, &M) != EOF) {
    uf_init();
    for (int k = 0; k < (int)(M); ++k) {
      int x, y;
      scanf("%d%d", &x, &y);
      x--, y--;
      uf_union(x, y);
    }
    memset((freq), (0), sizeof(freq));
    for (int i = 0; i < (int)(N); ++i) freq[uf_root(i)]++;
    map<int, int> mp;
    for (int j = 0; j < (int)(N + 1); ++j)
      if (freq[j]) mp[freq[j]]++;
    for (int i = 0; i < (int)(77777 + 1); ++i) dp[i] = 666666;
    dp[0] = 0;
    for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); ++it) {
      int step = it->first, num = it->second;
      for (int of = 0; of < (int)(step); ++of) {
        int K = 0;
        for (int i = of; i <= 77777; i += step) vi[K++] = dp[i];
        if (K <= 1) continue;
        solve(K, num + 1);
        for (int i = of; i <= 77777; i += step) dp[i] = vi[i / step];
      }
    }
    int res = 666666;
    for (int i = (1); i <= (int)(N); ++i)
      if (is_lucky(i)) res = min(res, dp[i]);
    if (res == 666666)
      printf("-1\n");
    else
      printf("%d\n", res - 1);
  }
}
