#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, ne, te[N], sz[N], c[N], f[N];
int fd(int u) { return u == te[u] ? u : te[u] = fd(te[u]); }
vector<int> split(int x) {
  vector<int> s;
  for (int k = 1; k <= x; k *= 2) {
    s.push_back(k), x -= k;
  }
  if (x) {
    s.push_back(x), x = 0;
  }
  return s;
}
bool check(int x) {
  for (; x; x /= 10) {
    if (x % 10 != 4 and x % 10 != 7) {
      return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> ne, f[0] = 0;
  for (int x = (1); x < (n + 1); ++x) {
    f[x] = N;
  }
  for (int u = (0); u < (n); ++u) {
    te[u] = u, sz[u] = 1;
  }
  for (int i = (0); i < (ne); ++i) {
    int u, v;
    cin >> u >> v, u = fd(--u), v = fd(--v);
    if (u != v) {
      sz[v] += sz[u], te[u] = v;
    }
  }
  for (int u = (0); u < (n); ++u) {
    if (fd(u) == u) {
      c[sz[u]] += 1;
    }
  }
  for (int x = (1); x < (n + 1); ++x) {
    for (const int &y : split(c[x])) {
      for (int i = (n + 1 - x * y) - 1; i >= (0); --i) {
        f[i + x * y] = min(f[i + x * y], f[i] + y);
      }
    }
  }
  int res = N;
  for (int x = (1); x < (n + 1); ++x) {
    if (check(x)) {
      res = min(res, f[x]);
    }
  }
  cout << (res == N ? -1 : res - 1) << '\n';
  return 0;
}
