#include <bits/stdc++.h>
using namespace std;
int a[100010], f[100010], g[100010], p[100010], w[100010], st[100010];
int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); }
int main() {
  int i, j, k, n, m, u, v, ans, can, low, top, base;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    p[i] = i;
    w[i] = 1;
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    u--, v--;
    if (Find(u) != Find(v)) {
      w[p[u]] += w[p[v]];
      p[p[v]] = p[u];
    }
  }
  for (i = m = 0; i < n; i++)
    if (Find(i) == i) a[m++] = w[Find(i)];
  sort(a, a + m);
  for (i = 0; i <= n; i++) f[i] = 1000000;
  f[0] = 0;
  for (i = 0; i < m; i = j + 1) {
    for (j = i; j + 1 < m && a[j] == a[j + 1]; j++)
      ;
    memcpy(g, f, sizeof(f));
    for (base = 0; base < a[i]; base++) {
      st[low = top = 0] = base;
      for (k = base + a[i]; k <= n; k += a[i]) {
        while ((k - st[low]) / a[i] > j - i + 1) low++;
        f[k] = min(f[k], g[st[low]] + (k - st[low]) / a[i]);
        while (low <= top && g[st[top]] + (k - st[top]) / a[i] >= g[k]) top--;
        st[++top] = k;
      }
    }
  }
  ans = 1000000;
  for (i = 1; i <= n; i++) {
    can = 1;
    for (j = i; j; j /= 10)
      if (j % 10 != 4 && j % 10 != 7) can = 0;
    if (can) ans = min(ans, f[i]);
  }
  ans == 1000000 ? puts("-1") : printf("%d\n", ans - 1);
  return 0;
}
