#include <bits/stdc++.h>
template <typename T>
inline void SWAP(T &a, T &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
template <typename T>
inline T ABS(const T &val) {
  return val < 0 ? -val : val;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T>
inline T MIN(const T &a, const T &b) {
  return a < b ? a : b;
}
const int INTinf = 2147483647;
const int nINTinf = 0 - 2147483648;
using namespace std;
int n, m;
vector<int> arr[100005];
int q, w;
map<int, int> mp;
bool met[100005];
int nom = 0;
vector<pair<int, int> > elems;
int dp[638][100005];
void rec(int pos) {
  met[pos] = true;
  nom++;
  for (int i = 0; i != arr[pos].size(); i++) {
    if (!met[arr[pos][i]]) {
      rec(arr[pos][i]);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i != m; i++) {
    scanf("%d %d", &q, &w);
    arr[--q].push_back(--w);
    arr[w].push_back(q);
  }
  memset(met, 0, sizeof(met));
  for (int i = 0; i != n; i++) {
    if (!met[i]) {
      nom = 0;
      rec(i);
      mp[nom]++;
    }
  }
  int cnt = 0;
  map<int, int>::iterator it = mp.begin();
  int tmp;
  while (it != mp.end()) {
    if (it->second > 2) {
      int kol = 0;
      tmp = it->second;
      bool good = 1;
      good &= tmp & 1;
      int val = it->first;
      while (tmp >>= 1) {
        elems.push_back(pair<int, int>(val, 1 << kol));
        kol++;
        good &= tmp & 1;
        val <<= 1;
      }
      if (good) {
        elems.push_back(pair<int, int>(val, 1 << kol));
      } else {
        tmp = it->first * (1 + it->second) - val;
        elems.push_back(pair<int, int>(tmp, tmp / it->first));
      }
    } else {
      elems.push_back(pair<int, int>(it->first, 1));
      if (it->second == 2) elems.push_back(pair<int, int>(it->first, 1));
    }
    it++;
  }
  cnt = elems.size();
  sort(elems.begin(), elems.end());
  int S = 0;
  for (int i = 0; i != cnt; i++) {
    dp[i][0] = 1000000;
  }
  for (int i = 0; i != elems.size(); i++) {
    tmp = elems[i].first;
    cnt = elems[i].second;
    S += tmp;
    for (int j = 1; j <= S; j++) {
      if (j >= tmp) {
        dp[i + 1][j] = MAX(dp[i][j], dp[i][j - tmp] - cnt);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
  int MMX = 0;
  for (int i = 1; i <= n; i++) {
    S = 1;
    tmp = i;
    while (tmp && S) {
      switch (tmp % 10) {
        case 4:
        case 7:
          tmp /= 10;
          break;
        default:
          S = 0;
          break;
      }
    }
    if (S) MMX = MAX(MMX, dp[elems.size()][i]);
  }
  if (MMX) {
    cout << 999999 - MMX << endl;
  } else
    cout << -1 << endl;
  return 0;
}
