#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 1e5 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 2010405347;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;
int n, m, a, b, k, p[MAX], sz[MAX], cnt[MAX], dp[450][MAX], ans;
pair<int, int> x[MAX];
bool lis[MAX];
void dfs(int nw) {
  if (nw > n) return;
  lis[nw] = 1;
  dfs(nw * 10 + 4);
  dfs(nw * 10 + 7);
  return;
}
int par(int z) {
  if (p[z] == z) return z;
  return p[z] = par(p[z]);
}
int f(int nw, int rem) {
  if (nw > k) return MAX;
  if (dp[nw][rem] != -1) return dp[nw][rem];
  int bt = min(x[nw].second, rem / x[nw].first);
  if (bt * x[nw].first == rem) return dp[nw][rem] = bt;
  int ret = MAX;
  for (int i = max(0, bt - 3); i <= bt; ++i)
    ret = min(ret, f(nw + 1, rem - i * x[nw].first) + i);
  return dp[nw][rem] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  dfs(0);
  for (int i = 1; i <= n; ++i) p[i] = i, sz[i] = 1;
  while (m--) {
    cin >> a >> b;
    a = par(a), b = par(b);
    if (a != b) {
      p[a] = b;
      sz[b] += sz[a];
    }
  }
  for (int i = 1; i <= n; ++i)
    if (par(i) == i) ++cnt[sz[i]];
  for (int i = n; i >= 1; --i)
    if (cnt[i]) {
      if (lis[i]) return cout << "0\n", 0;
      x[++k] = {i, cnt[i]};
    }
  memset(dp, -1, sizeof dp);
  ans = MAX;
  for (int i = 1; i <= n; ++i)
    if (lis[i]) {
      ans = min(ans, f(1, i) - 1);
      if (ans == 1) return cout << "1\n", 0;
    }
  if (ans > n) ans = -1;
  cout << ans << '\n';
  return 0;
}
