#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, m, a, b, ans, p[100010];
int sz[100010], dp[100010], cnt[100010];
bool is(int x) {
  while (x != 0) {
    if (!(x % 10 == 4 || x % 10 == 7)) return false;
    x /= 10;
  }
  return true;
}
int get(int v) { return v == p[v] ? v : p[v] = get(p[v]); }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) p[i] = i;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    p[get(a)] = get(b);
  }
  for (int i = 1; i <= n; ++i) ++sz[get(i)];
  for (int i = 1; i <= n; ++i) ++cnt[sz[i]], dp[i] = 1000000007;
  for (int i = 1; i <= n; ++i)
    for (int j = 1, x = cnt[i]; x > 0; j <<= 1) {
      int add = min(x, j);
      int step = add * i;
      x -= add;
      for (int k = n - step; k >= 0; --k)
        dp[k + step] = min(dp[k + step], dp[k] + add);
    }
  ans = 1000000007;
  for (int i = 1; i <= n; ++i)
    if (is(i)) ans = min(ans, dp[i]);
  cout << (ans > n ? -1 : ans - 1) << endl;
}
