#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, x, y, t, an;
int f[100010], s[100010], g[100010], w[100010];
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
inline bool ju(int x) {
  for (; x; x /= 10) {
    int A = x % 10;
    if (A != 4 && A != 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++) s[get(i)]++;
  memset(w, 120, sizeof(w));
  an = w[0], w[0] = 0;
  for (i = 1; i <= n; i++)
    if (i == get(i)) {
      if (1ll * s[i] * s[i] <= n)
        g[s[i]]++;
      else
        for (j = n; j >= s[i]; j--) w[j] = min(w[j], w[j - s[i]] + 1);
    }
  for (i = 1; i <= n; i++)
    if (g[i]) {
      for (j = 0; j <= i - 1; j++) {
        int l = 1, r = 0, u;
        for (k = j, u = 1; k <= n; k += i, u++) {
          int A = w[k] - u;
          for (; r >= l && s[r] >= A; r--)
            ;
          s[++r] = A, f[r] = u;
          if (f[l] + g[i] < u) l++;
          w[k] = s[l] + u;
        }
      }
    }
  for (i = 1; i <= n; i++)
    if (ju(i)) an = min(an, w[i]);
  printf("%d\n", an > 1e9 ? -1 : an - 1);
  return 0;
}
