#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int p[N];
int f(int u) { return u == p[u] ? u : p[u] = f(p[u]); }
int dp[N], cc[N], sz[N];
void update(int c, int am, int v) {
  for (int i = v; i >= c; i--) {
    dp[i] = min(dp[i], dp[i - c] + am);
  }
}
bool judge(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int fx = f(x), fy = f(y);
    if (fx != fy) p[fx] = fy;
  }
  for (int i = 1; i <= n; i++) {
    int fi = f(i);
    cc[fi]++;
  }
  for (int i = 1; i <= n; i++) {
    sz[cc[i]]++;
  }
  memset(dp, 63, sizeof(dp));
  int oo = dp[0];
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (sz[i]) {
      for (int k = 1; k < sz[i]; sz[i] -= k, k <<= 1) {
        update(k * i, k, n);
      }
      if (sz[i]) {
        update(sz[i] * i, sz[i], n);
      }
    }
  }
  int ret = oo;
  for (int i = 1; i <= n; i++) {
    if (judge(i)) {
      ret = min(ret, dp[i]);
    }
  }
  if (ret == oo) ret = 0;
  printf("%d\n", ret - 1);
  return 0;
}
