#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100050;
const int CURR = 1;
const int OLD = 0;
const int INF = (int)1e9;
struct MaxQueue {
  deque<int> d;
  queue<int> q;
  void push(int v) {
    while (((int)d.size()) && d.back() > v) d.pop_back();
    d.push_back(v);
    q.push(v);
  }
  void pop() {
    if (((int)d.size()) && d.front() == q.front()) d.pop_front();
    q.pop();
  }
  int getMin() { return ((int)d.size()) ? d.front() : 0; }
  void clear() {
    d.clear();
    while (((int)q.size())) q.pop();
  }
  int size() { return ((int)q.size()); }
};
struct Item {
  int u, w, c;
};
int n, m;
vector<int> V[MAXN];
map<int, int> H;
bool isLucky(int x) {
  while (x) {
    if (x % 10 != 4 && x % 10 != 7) return false;
    x /= 10;
  }
  return true;
}
int solve(int C, const vector<Item> &I) {
  MaxQueue M;
  int n = ((int)I.size());
  vector<int> dp[2];
  for (int i = (0); i < (int)(2); i++) dp[i].resize(C + 1);
  for (int j = (0); j < (int)(C + 1); j++) dp[OLD][j] = j == 0 ? 0 : INF;
  for (int i = (0); i < (int)(n); i++) {
    int w = I[i].w;
    int c = I[i].c;
    int u = I[i].u;
    for (int j = (0); j < (int)(C + 1); j++) {
      if (j < w) V[j].clear();
      V[j % w].push_back(dp[OLD][j] - ((int)V[j % w].size()) * c);
    }
    for (int j = (0); j < (int)(min(w, C + 1)); j++) {
      for (int z = j, p = 0; z < C + 1; z += w, p++) {
        M.push(V[j][p]);
        while (((int)M.size()) > u + 1) M.pop();
        int g = M.getMin() + p * c;
        dp[CURR][z] = g;
      }
      M.clear();
    }
    swap(dp[OLD], dp[CURR]);
  }
  int ans = MAXN;
  for (int i = (1); i < (int)(C + 1); i++) {
    if (isLucky(i)) {
      ans = min(ans, dp[OLD][i]);
    }
  }
  return ans == MAXN ? -1 : ans - 1;
}
int uf[MAXN];
void uf_init() { memset(uf, -1, sizeof(uf)); }
int uf_find(int x) { return uf[x] < 0 ? x : uf[x] = uf_find(uf[x]); }
bool uf_join(int x, int y) {
  x = uf_find(x);
  y = uf_find(y);
  if (x == y) return false;
  if (uf[x] > uf[y]) swap(x, y);
  uf[x] += uf[y];
  uf[y] = x;
  return true;
}
int main() {
  while (scanf("%d %d", &n, &m) >= 1) {
    H.clear();
    uf_init();
    for (int i = (0); i < (int)(m); i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      --a;
      --b;
      uf_join(a, b);
    }
    for (int i = (0); i < (int)(n); i++) {
      if (uf[i] < 0) {
        H[-uf[i]]++;
      }
    }
    vector<Item> I;
    for (auto it : H) {
      I.push_back((Item){it.second, it.first, 1});
    }
    printf("%d\n", solve(n, I));
  }
  return 0;
}
