#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 100100;
int n, m, l[MAXN], s[MAXN], d[MAXN];
vector<int> st, cur;
int leader(int v) {
  if (l[v] != v) l[v] = leader(l[v]);
  return l[v];
}
void put(int v, int value) {
  if (d[v] > INF / 2) cur.push_back(v);
  d[v] = min(d[v], value);
}
bool lucky(int x) {
  if (x == 0) return false;
  while (x > 0) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) {
    l[i] = i;
    s[i] = 1;
  }
  for (int i = 0; i < (int)(m); i++) {
    int v, u;
    cin >> v >> u;
    v = leader(v - 1);
    u = leader(u - 1);
    if (rand() % 2 == 0) swap(v, u);
    if (v != u) {
      l[u] = v;
      s[v] += s[u];
    }
  }
  map<int, int> mm;
  for (int i = 0; i < (int)(n); i++)
    if (leader(i) == i) mm[s[i]]++;
  vector<pair<int, int> > a(mm.begin(), mm.end());
  memset(d, 60, sizeof d);
  sort(a.rbegin(), a.rend());
  put(0, -1);
  st = cur;
  for (int i = 0; i < (int)(a.size()); i++)
    for (int c = 1; c <= a[i].second; c *= 2) {
      cur.clear();
      for (int j = (int)(st.size()) - 1; j >= 0; j--)
        put(a[i].first * c + st[j], d[st[j]] + c);
      st.insert(st.end(), cur.begin(), cur.end());
    }
  int ans = INF;
  for (int i = 0; i < (int)(n + 1); i++)
    if (lucky(i)) ans = min(ans, d[i]);
  if (ans > INF / 2) ans = -1;
  cout << ans << endl;
  return 0;
}
