#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int n, m;
int head[max_n];
int size[max_n];
void init() {
  for (int i = 0; i < n; i++) {
    head[i] = i;
    size[i] = 1;
  }
}
int trace(int i) { return (i == head[i]) ? i : (head[i] = trace(head[i])); }
void merge(int i, int j) {
  int x = trace(i);
  int y = trace(j);
  if (x != y) {
    if (size[x] > size[y]) {
      head[y] = x;
      size[x] = size[x] + size[y];
    } else {
      head[x] = y;
      size[y] = size[x] + size[y];
    }
  }
}
void parce() {
  int a, b;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    merge(a - 1, b - 1);
  }
}
bool is_lucky(int i) {
  int x = i, y = (i / 10) * 10;
  bool lucky = true;
  while (x > 0) {
    int d = x - y;
    if (!(d == 4 || d == 7)) {
      lucky = false;
      break;
    }
    x = x / 10;
    y = (x / 10) * 10;
  }
  return lucky;
}
void solve() {
  map<int, int> M;
  for (int i = 0; i < n; i++) {
    if (i == trace(i)) M[size[i]]++;
  }
  vector<pair<int, int> > a;
  for (auto it = M.begin(); it != M.end(); it++) {
    int sz = it->first, cnt = it->second;
    int i = 1;
    while (cnt >= i) {
      a.push_back(pair<int, int>(sz * i, i));
      cnt -= i;
      i <<= 1;
    }
    if (cnt) a.push_back(pair<int, int>(sz * (cnt), cnt));
  }
  int dp[n];
  int ans = INF;
  for (int i = 1; i <= n; i++) dp[i] = INF;
  dp[0] = 0;
  for (auto it = a.begin(); it != a.end(); it++) {
    int sum = it->first, cnt = it->second;
    for (int k = n; k >= sum; k--) {
      if (dp[k - sum] < INF) dp[k] = min(dp[k], dp[k - sum] + cnt);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (is_lucky(i)) ans = min(ans, dp[i]);
  }
  if (ans > n) ans = 0;
  cout << ans - 1 << endl;
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  parce();
  solve();
}
