#include <bits/stdc++.h>
using namespace std;
int N, M;
pair<int, int> dsu[100001];
int sum_dsu[100001];
vector<int> V, valid;
vector<pair<int, int> > trick;
bool lucky[100001];
int dp[100001];
int Find(int A) {
  if (dsu[A].first == A)
    return A;
  else
    return dsu[A].first = Find(dsu[A].first);
}
void Union(int A, int B) {
  A = Find(A);
  B = Find(B);
  if (A == B) return;
  if (dsu[A].second < dsu[B].second) swap(A, B);
  if (dsu[A].second == dsu[B].second) dsu[A].second++;
  dsu[B].first = A;
  sum_dsu[A] += sum_dsu[B];
}
void generate_lucky() {
  queue<int> tmp;
  int ten = 1;
  tmp.push(0);
  for (int i = 1; i <= 5; i++) {
    int t = tmp.size();
    while (t--) {
      int num = tmp.front();
      tmp.pop();
      tmp.push(num + 4 * ten);
      tmp.push(num + 7 * ten);
      lucky[num + 4 * ten] = true;
      lucky[num + 7 * ten] = true;
    }
    ten *= 10;
  }
}
void adjust() {
  int memo = 1;
  for (int i = 1; i < V.size(); i++) {
    if (V[i] == V[i - 1])
      memo++;
    else {
      int two = 1;
      while (memo >= two) {
        memo -= two;
        trick.push_back(make_pair(V[i - 1] * two, two));
        two *= 2;
      }
      if (memo != 0) trick.push_back(make_pair(V[i - 1] * memo, memo));
      memo = 1;
    }
  }
  int two = 1;
  while (memo >= two) {
    memo -= two;
    trick.push_back(make_pair(V.back() * two, two));
    two *= 2;
  }
  if (memo != 0) trick.push_back(make_pair(V.back() * memo, memo));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> N >> M;
  generate_lucky();
  for (int i = 1; i <= N; i++) {
    dsu[i].first = i;
    sum_dsu[i] = 1;
  }
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    Union(a, b);
  }
  for (int i = 1; i <= N; i++) {
    if (dsu[i].first == i) V.push_back(sum_dsu[i]);
  }
  sort(V.begin(), V.end());
  adjust();
  for (auto G : V) {
    if (lucky[G]) {
      cout << "0";
      return 0;
    }
  }
  int ok = 999999;
  for (auto GG : trick) {
    int G = GG.first, cost = GG.second;
    for (int H = 77777; H >= 0; H--) {
      if (dp[H] == 0 && H != 0) continue;
      if (G + H > 77777) continue;
      if (dp[G + H] == 0) {
        dp[G + H] = dp[H] + cost;
      } else {
        dp[G + H] = min(dp[G + H], dp[H] + cost);
      }
      if (lucky[G + H]) {
        if (ok == 999999)
          ok = dp[G + H];
        else
          ok = min(ok, dp[G + H]);
      }
    }
  }
  if (ok == 999999)
    cout << "-1";
  else
    cout << ok - 1;
  return 0;
}
