#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = 1e5 + 5, inf = 1e9 + 69, delta = 1e9 + 7, max_sum = 10000 + 5,
          SQRT = 333;
inline void in_out_optimize() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
int inp() {
  int x;
  cin >> x;
  return x;
}
vector<int> adj[maxn];
bool mark[maxn];
int dp[maxn], c[SQRT];
int n, m;
void add_edge(int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void input() {
  cin >> n >> m;
  while (m--) add_edge(inp(), inp());
}
int DFS(int v) {
  int sz = 0;
  stack<int> q;
  q.push(v);
  mark[v] = true;
  while (q.size()) {
    v = q.top();
    q.pop();
    sz++;
    for (auto u : adj[v])
      if (!mark[u]) {
        mark[u] = true;
        q.push(u);
      }
  }
  return sz;
}
void mini_updt(int x, int cnt) {
  for (int r = 0; r < x; r++) {
    set<pair<int, int> > s;
    for (int i = 0; i * x + r <= n; i++) {
      int pos = i * x + r;
      while (!s.empty() and (pos - (*(s.begin())).second) / x > cnt)
        s.erase(s.begin());
      s.insert(make_pair(dp[pos] - i, pos));
      pair<int, int> pi = (*(s.begin()));
      dp[pos] = pi.first + (pos - r) / x;
    }
  }
}
int lucky[] = {7,     4,     77,    74,    47,    44,    777,   774,   747,
               744,   477,   474,   447,   444,   7777,  7774,  7747,  7744,
               7477,  7474,  7447,  7444,  4777,  4774,  4747,  4744,  4477,
               4474,  4447,  4444,  77777, 77774, 77747, 77744, 77477, 77474,
               77447, 77444, 74777, 74774, 74747, 74744, 74477, 74474, 74447,
               74444, 47777, 47774, 47747, 47744, 47477, 47474, 47447, 47444,
               44777, 44774, 44747, 44744, 44477, 44474, 44447, 44444};
void big_updt(int x) {
  for (int i = n; i >= x; i--) dp[i] = min(dp[i], 1 + dp[i - x]);
}
void make_luckies() {
  queue<string> q;
  q.push("");
  while (q.front().size() < 6) {
    string s = q.front();
    cout << s << ", ";
    string s2 = s + '4';
    s += '7';
    q.pop();
    q.push(s);
    q.push(s2);
  }
}
bool came[maxn];
int main() {
  in_out_optimize();
  fill(dp, dp + maxn, inf);
  dp[0] = -1;
  input();
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      int a = (DFS(i));
      if (a < SQRT)
        c[a]++, came[a] = true;
      else
        big_updt(a);
    }
  for (int i = 0; i < 62; i++)
    if (came[lucky[i]] > 0) {
      cout << 0;
      exit(0);
    }
  for (int i = 1; i < SQRT; i++)
    if (c[i]) mini_updt(i, c[i]);
  int ans = inf;
  for (int i = 0; i < 62; i++) ans = min(ans, dp[lucky[i]]);
  if (ans >= inf)
    cout << -1 << '\n';
  else
    cout << max(0, ans) << '\n';
  return 0;
  cout << "DONE" << endl;
  while (true) {
    int a = inp();
    cout << dp[a] << endl;
  }
}
