#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e6, T = (1 << 20) + 10, M = 998244353, P = 6151,
          SQ = 280, lg = 64;
int pr[N], sz[N], num[N], dp[4][N];
int find(int x) {
  if (pr[x] == x) return x;
  return (pr[x] = find(pr[x]));
}
deque<int> dq[N];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  set<int> s, st;
  cin >> n >> m;
  bool b = true;
  for (int i = 1; i <= n; i++) pr[i] = i, sz[i] = 1, dp[b][i] = OO, s.insert(i);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x = find(x), y = find(y);
    if (x != y) pr[x] = y, sz[y] += sz[x], s.erase(x);
  }
  for (auto u : s) st.insert(sz[u]), num[sz[u]]++;
  int mx = 0;
  for (int i = 1; i < 6; i++) {
    for (int msk = 0; msk < (1 << i); msk++) {
      int t = 0;
      for (int j = 0; j < i; j++) {
        t *= 10;
        if (msk & (1 << j))
          t += 4;
        else
          t += 7;
      }
      if (t > n) continue;
      mx = max(mx, t);
      if (num[t] != 0) return cout << 0, 0;
    }
  }
  dp[b][0] = 0;
  for (auto u : st) {
    b ^= 1;
    for (int i = 0; i < u; i++) dq[i].clear();
    for (int i = 0; i <= mx; i++) {
      int g = i % u;
      while ((int)dq[g].size() &&
             dp[b ^ 1][dq[g].back()] + (i - dq[g].back()) / u > dp[b ^ 1][i])
        dq[g].pop_back();
      dq[g].push_back(i);
      while ((int)dq[g].size() && (i - dq[g].front()) / u > num[u])
        dq[g].pop_front();
      dp[b][i] = dp[b ^ 1][dq[g].front()] + (i - dq[g].front()) / u;
    }
  }
  int ans = OO;
  for (int i = 1; i < 6; i++) {
    for (int msk = 0; msk < (1 << i); msk++) {
      int t = 0;
      for (int j = 0; j < i; j++) {
        t *= 10;
        if (msk & (1 << j))
          t += 4;
        else
          t += 7;
      }
      if (t > mx) continue;
      ans = min(ans, dp[b][t]);
    }
  }
  if (ans == OO) return cout << -1, 0;
  cout << ans - 1 << endl;
  return 0;
}
