#include <bits/stdc++.h>
using namespace std;
long n, m, w[201000], sz[201000];
long a, b;
long calc[200100];
long t;
vector<pair<long, long> > v;
long ts, tc;
long ans;
long gett(long x) {
  if (w[x] == x) return x;
  return w[x] = gett(w[x]);
}
bool nice(long x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
void merg(long a, long b) {
  if (rand() % 2) swap(a, b);
  sz[a] += sz[b];
  w[b] = a;
}
long bst[200000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    w[i] = i;
    sz[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (gett(a) == gett(b)) continue;
    merg(gett(a), gett(b));
  }
  for (int i = 1; i <= n; i++) {
    if (w[i] == i) {
      calc[sz[i]]++;
    }
  }
  bst[0] = 0;
  for (int i = 1; i <= n; i++) bst[i] = 1e9;
  for (int i = 1; i <= 100000; i++) {
    if (calc[i] == 0) continue;
    t = 1;
    while (calc[i] >= t) {
      v.push_back(make_pair(t * i, t));
      calc[i] -= t;
      t *= 2;
    }
    if (calc[i]) v.push_back(make_pair(calc[i] * i, calc[i]));
  }
  for (int i = 0; i < v.size(); i++)
    for (int j = 100000; j + 1; --j) {
      ts = v[i].first + j;
      tc = bst[j] + v[i].second;
      bst[ts] = min(bst[ts], tc);
    }
  ans = 1e9;
  for (int i = 1; i <= n; i++)
    if (nice(i)) ans = min(ans, bst[i]);
  if (ans > 1e8) ans = 0;
  cout << ans - 1 << endl;
  cin.get();
  cin.get();
  return 0;
}
