#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
int v[64], f[100010];
int d[2] = {4, 7};
int s[100010], cnt[100010], a[100010], nn;
void solve() {
  f[0] = 0;
  for (int i = 1; i <= nn; ++i) {
    int k = 1;
    while (s[a[i]]) {
      if (k >= s[a[i]]) k = s[a[i]];
      s[a[i]] -= k;
      for (int j = n; j >= k * a[i]; --j) f[j] = min(f[j], f[j - k * a[i]] + k);
      k <<= 1;
    }
  }
  int ans = 10000000;
  for (int i = 0; v[i] <= n && i < tot; ++i) ans = min(ans, f[v[i]]);
  if (ans == 10000000)
    puts("-1");
  else
    printf("%d\n", ans - 1);
}
int find(int x) {
  int ret = x, t;
  while (ret != s[ret]) ret = s[ret];
  while (s[x] != ret) {
    t = s[x];
    s[x] = ret;
    x = t;
  }
  return ret;
}
void init() {
  tot = 0;
  for (int i = 1; i <= 5; ++i)
    for (int j = 0; j < (1 << i); ++j, ++tot) {
      int l = 0, t = j;
      while (l < i) {
        v[tot] = v[tot] * 10 + d[t & 1];
        t >>= 1;
        ++l;
      }
    }
  sort(v, v + tot);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) s[i] = i, f[i] = 10000000;
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u = find(u), v = find(v);
    if (u != v) s[u] = v;
  }
  for (int i = 1; i <= n; ++i) ++cnt[find(i)];
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; ++i)
    if (cnt[i]) ++s[cnt[i]];
  nn = 0;
  for (int i = 1; i <= n; ++i)
    if (s[i]) a[++nn] = i;
  solve();
}
int main() {
  init();
  return 0;
}
