#include <bits/stdc++.h>
using namespace std;
int f[100001], c[100001], s[100001], dp[100001];
int find(int x) {
  if (f[x] == 0) return x;
  f[x] = find(f[x]);
  return f[x];
}
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return;
  f[fx] = fy;
  c[fy] += c[fx];
  c[fx] = 0;
}
bool lucky(int x) {
  while (x > 0) {
    int k = x % 10;
    if ((k != 4) && (k != 7)) return false;
    x /= 10;
  }
  return true;
}
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    c[i] = 1;
    dp[i] = n + 1;
  }
  for (int i = 1; i <= m; ++i) {
    int j, k;
    scanf("%d %d", &j, &k);
    merge(j, k);
  }
  for (int i = 1; i <= n; ++i)
    if (c[i] > 0) ++s[c[i]];
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 0) continue;
    int j = 1, k = s[i];
    while (k > 0) {
      j = min(j, k);
      k -= j;
      for (int p = n; p >= i * j; --p) dp[p] = min(dp[p], dp[p - i * j] + j);
      j *= 2;
    }
  }
  int ans = n;
  for (int i = 1; i <= n; ++i)
    if (lucky(i)) ans = min(ans, dp[i] - 1);
  if (ans == n) ans = -1;
  printf("%d\n", ans);
  return 0;
}
