#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
int lucky(int x) { return x == 4 || x == 7; }
bool can[N];
int cc[N], dp[N];
bool lucky_digit(int x) {
  bool is = 1;
  while (x) {
    if (!lucky(x % 10)) {
      is = 0;
      break;
    }
    x /= 10;
  }
  return is;
}
int par[N], sz[N];
int f(int x) {
  if (x == par[x]) return x;
  return par[x] = f(par[x]);
}
void merge(int a, int b) {
  a = f(a), b = f(b);
  if (a == b) return;
  par[b] = a;
  sz[a] += sz[b];
}
void cal(int n) {
  int sz = 0, nsz;
  for (int i = 1; i <= n; ++i) dp[i] = 1e9;
  for (int i = 1; i <= n; ++i) {
    if (!cc[i]) continue;
    nsz = sz + cc[i] * i;
    int sum = 0;
    for (int b = 1; sum + b <= cc[i]; b *= 2) {
      sum += b;
      int lim = b * i;
      for (int j = nsz; j - lim >= 0; --j) {
        dp[j] = min(dp[j], dp[j - lim] + b);
      }
    }
    sum = cc[i] - sum;
    if (sum > 0) {
      int lim = sum * i;
      int b = sum;
      for (int j = nsz; j - lim >= 0; --j) {
        dp[j] = min(dp[j], dp[j - lim] + b);
      }
    }
    sz = nsz;
  }
}
int main() {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) par[i] = i, sz[i] = 1;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    merge(a, b);
  }
  for (int i = 1; i <= n; ++i)
    if (f(i) == i) {
      ++cc[sz[i]];
    }
  cal(n);
  int ret = 1e9;
  for (int i = 1; i <= n; ++i) {
    if (lucky_digit(i)) ret = min(ret, dp[i]);
  }
  if (ret == 1e9) ret = 0;
  printf("%d\n", ret - 1);
  return 0;
}
