#include <bits/stdc++.h>
const int INF = 1 << 30;
int p[100001], d[100001], cn[100001];
std::vector<int> w, c;
int find(int x) { return (p[x] == x ? x : p[x] = find(p[x])); }
int main() {
  int n, m, a, b;
  scanf("%d %d", &n, &m);
  for (int i = 0; i <= n; ++i) cn[i] = 0;
  for (int i = 0; i < n; ++i) p[i] = i;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    a = find(a - 1), b = find(b - 1);
    if (a != b) p[a] = b;
  }
  c.reserve(n + 1);
  w.reserve(20000);
  for (int i = 0; i < n; ++i) cn[find(p[i])]++;
  for (int i = 0; i < n; ++i)
    if (cn[i] > 0) c.push_back(cn[i]);
  for (int i = 0; i <= n; ++i) cn[i] = 0;
  for (int i = 0; i < c.size(); ++i) ++cn[c[i]];
  c.clear();
  for (int i = 0; i <= n; ++i)
    if (cn[i] > 0) {
      a = 1;
      while (cn[i] >= a) {
        c.push_back(a);
        w.push_back(a * i);
        cn[i] -= a;
        a <<= 1;
      }
      if (cn[i] > 0) {
        c.push_back(cn[i]);
        w.push_back(cn[i] * i);
      }
    }
  int N = c.size();
  for (int i = 1; i <= n; ++i) d[i] = INF;
  d[0] = 0;
  for (int i = 1; i <= N; ++i)
    for (int j = n; j >= w[i - 1]; --j)
      if (d[j - w[i - 1]] + c[i - 1] < d[j]) d[j] = d[j - w[i - 1]] + c[i - 1];
  int ans = INF, mod;
  bool good;
  for (int i = 4; i <= n; ++i) {
    if (ans <= d[i]) continue;
    a = i;
    good = true;
    while (a > 0 && good) {
      mod = a - (a / 10) * 10;
      if (!(mod == 4 || mod == 7)) good = false;
      a /= 10;
    }
    if (good) ans = d[i];
  }
  printf("%d", (ans < INF ? ans - 1 : -1));
  return 0;
}
