#include <bits/stdc++.h>
using namespace std;
int pre[100005];
int ct[100005];
int vis[100005];
int v[100005], c[100005];
int dp[100005];
int n;
int ans;
int check(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return 0;
    x /= 10;
  }
  return 1;
}
int MIN(int a, int b) { return a < b ? a : b; }
int zop(int value, int num) {
  for (int i = n; i >= value; i--) {
    dp[i] = MIN(dp[i], dp[i - value] + num);
  }
  return 0;
}
int fd(int x) {
  int r = x;
  while (pre[r] != r) r = pre[r];
  int temp;
  while (x != r) {
    temp = pre[x];
    pre[x] = r;
    x = temp;
  }
  return r;
}
int main(int argc, char *argv[]) {
  int m, a, b, gs;
  while (cin >> n >> m) {
    gs = 0, ans = 100005;
    for (int i = 1; i <= n; i++) ct[i] = 0;
    for (int i = 1; i <= n; i++) pre[i] = i;
    for (int i = 1; i <= n; i++) vis[i] = 0;
    for (int i = 1; i <= n; i++) dp[i] = 100005;
    dp[0] = -1;
    for (int i = 1; i <= m; i++) {
      cin >> a >> b;
      if (fd(a) != fd(b)) {
        pre[fd(a)] = fd(b);
      }
    }
    for (int i = 1; i <= n; i++) ct[fd(i)]++;
    for (int i = 1; i <= n; i++)
      if (ct[i]) vis[ct[i]]++;
    for (int i = 1; i <= n; i++) {
      if (vis[i]) v[gs] = i, c[gs++] = vis[i];
    }
    for (int i = 0; i < gs; i++) {
      if (v[i] * c[i] >= n) c[i] = n / v[i];
      int num = 1;
      while (c[i]) {
        if (num <= c[i])
          zop(num * v[i], num), c[i] -= num, num <<= 1;
        else
          zop(c[i] * v[i], c[i]), c[i] = 0;
      }
    }
    for (int i = 1; i <= n; i++)
      if (check(i)) ans = MIN(dp[i], ans);
    if (ans != 100005)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
