#include <bits/stdc++.h>
using namespace std;
int pset[100005], sze[100005];
int fs(int a) { return (a == pset[a] ? a : pset[a] = fs(pset[a])); }
int freq[100005];
pair<int, int> num[100005];
int dp[455][100005];
struct monoque {
  deque<pair<int, int> > dq;
  void push(pair<int, int> u) {
    while (!dq.empty()) {
      auto v = dq.back();
      if (v.first < u.first) break;
      dq.pop_back();
    }
    dq.push_back(u);
  }
  pair<int, int> front(int i) {
    while (true) {
      auto v = dq.front();
      if (v.second >= i) return v;
      dq.pop_front();
    }
  }
};
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (n); i++) pset[i] = i;
  for (int i = (1); i <= (m); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (fs(u) == fs(v)) continue;
    pset[fs(u)] = fs(v);
  }
  for (int i = (1); i <= (n); i++) sze[fs(i)]++;
  int ns = 0;
  for (int i = (1); i <= (n); i++)
    if (sze[i]) freq[sze[i]]++;
  for (int i = (1); i <= (n); i++)
    if (freq[i]) num[++ns] = {i, freq[i]};
  for (int i = (0); i <= (ns); i++)
    for (int j = (0); j <= (n); j++) dp[i][j] = 1000000000;
  dp[0][0] = 0;
  for (int i = (1); i <= (ns); i++) {
    int v = num[i].first, f = num[i].second;
    for (int j = (0); j <= (v - 1); j++) {
      monoque mq;
      for (int k = j; k <= n; k += v) {
        mq.push({dp[i - 1][k] - k / v, k / v});
        auto u = mq.front(k / v - f);
        dp[i][k] = u.first + u.second + (k / v - u.second);
      }
    }
  }
  int ans = 1000000000;
  for (int j = (1); j <= (n); j++) {
    int t = j;
    bool f = 1;
    while (t && f) f &= (t % 10 == 4 || t % 10 == 7), t /= 10;
    if (f) ans = min(ans, dp[ns][j] - 1);
  }
  printf("%d\n", ans >= n ? -1 : ans);
  return 0;
}
