#include <bits/stdc++.h>
using namespace std;
int f[100005], Q[100005], S[100005], sum[100005], g[100005], a[100005],
    b[100005];
int n, m, i, x, y, k, mod, h, t, ans;
int get(int u) { return f[u] == u ? u : f[u] = get(f[u]); }
int check(int x) {
  for (; x; x /= 10)
    if (x % 10 != 4 && x % 10 != 7) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) f[i] = i;
  for (i = 1; i <= m; i++) scanf("%d%d", &x, &y), f[get(x)] = get(y);
  for (i = 1; i <= n; i++) sum[get(i)]++;
  for (i = 1; i <= n; i++)
    if (f[i] == i) S[++*S] = sum[i];
  sort(S + 1, S + *S + 1);
  k = 1;
  m = 0;
  for (i = 2; i <= (*S) + 1; i++)
    if (S[i] != S[i - 1]) a[++m] = S[i - 1], b[m] = i - k, k = i;
  f[0] = 0;
  for (i = 1; i <= n; i++) f[i] = 1e9;
  for (i = 1; i <= m; i++) {
    for (k = 0; k <= n; k++) g[k] = f[k];
    for (mod = 0; mod < a[i]; mod++) {
      h = t = 1;
      Q[1] = mod;
      for (k = mod + a[i]; k <= n; k += a[i]) {
        for (; h <= t && (k - Q[h]) / a[i] > b[i]; h++)
          ;
        if (h <= t) f[k] = min(f[k], g[Q[h]] + (k - Q[h]) / a[i]);
        for (; h <= t && g[k] <= g[Q[t]] + (k - Q[t]) / a[i]; t--)
          ;
        Q[++t] = k;
      }
    }
  }
  ans = 1e9;
  for (i = 1; i <= n; i++)
    if (check(i)) ans = min(ans, f[i]);
  printf("%d\n", ans == 1e9 ? -1 : ans - 1);
}
