#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int first = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    first = first * 10 + ch - '0';
    ch = getchar();
  }
  return first * f;
}
int n, m, f[100010], s[100010], t[100010], S = (INT_MAX >> 2);
inline int fa(int first) {
  return f[first] == first ? first : (f[first] = fa(f[first]));
}
inline int ff(int first) {
  for (; first; first /= 10)
    if (first % 10 != 4 && first % 10 != 7) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1, first, second; i <= m; i++)
    scanf("%d%d", &first, &second), f[fa(first)] = fa(second);
  for (int i = 1; i <= n; i++) s[fa(i)]++;
  for (int i = 1; i <= n; i++) t[s[i]]++;
  for (int i = 1; i <= n; i++) f[i] = (INT_MAX >> 2);
  for (int i = 1; i <= n; i++)
    if (t[i]) {
      int k = t[i];
      for (int h = 1; k; h += h) {
        k -= (h = min(h, k));
        int hi = h * i;
        for (int j = n - hi; j >= 0; j--) f[j + hi] = min(f[j + hi], f[j] + h);
      }
    }
  for (int i = 1; i <= n; i++)
    if (ff(i)) S = min(S, f[i]);
  if (S == (INT_MAX >> 2))
    puts("-1");
  else
    printf("%d\n", S - 1);
}
