#include <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
bool visited[100005];
int freq[100005];
int arr[100005][2];
int dp[100005];
int n;
vector<int> lucky;
void getlucky(int num) {
  if (num <= n)
    lucky.push_back(num);
  else
    return;
  getlucky(num * 10 + 4);
  getlucky(num * 10 + 7);
}
int dfs(int node) {
  visited[node] = 1;
  int ret = 1;
  for (auto &x : g[node])
    if (!visited[x]) ret += dfs(x);
  return ret;
}
bool islucky(int num) {
  while (num) {
    if (num % 10 != 4 && num % 10 != 7) return false;
    num /= 10;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int m;
  cin >> n >> m;
  getlucky(4), getlucky(7);
  sort(lucky.begin(), lucky.end());
  if (lucky.empty()) {
    cout << -1;
    return 0;
  }
  int maxNum = lucky.back();
  while (m--) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) freq[dfs(i)]++;
  }
  int N = 0;
  for (int i = 1; i <= maxNum; i++) {
    dp[i] = 1e9;
    if (!freq[i]) continue;
    if (islucky(i)) {
      cout << 0;
      return 0;
    }
    arr[N][0] = i;
    arr[N][1] = freq[i];
    N++;
  }
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 1; sum + j < arr[i][1]; j *= 2) {
      for (int k = maxNum; k >= 1; k--) {
        if (k - arr[i][0] * j < 0) break;
        dp[k] = min(dp[k], dp[k - arr[i][0] * j] + j);
      }
    }
    int j = arr[i][1] - sum;
    if (j) {
      for (int k = maxNum; k >= 1; k--) {
        if (k - arr[i][0] * j < 0) break;
        dp[k] = min(dp[k], dp[k - arr[i][0] * j] + j);
      }
    }
  }
  int ans = 1e9;
  for (auto &x : lucky) {
    ans = min(ans, dp[x]);
  }
  if (ans == 1e9)
    ans = -1;
  else
    ans--;
  cout << ans;
  return 0;
}
