#include <bits/stdc++.h>
using namespace std;
int happy[62] = {
    4,     7,     44,    47,    74,    77,    444,   447,   474,   477,   744,
    747,   774,   777,   4444,  4447,  4474,  4477,  4744,  4747,  4774,  4777,
    7444,  7447,  7474,  7477,  7744,  7747,  7774,  7777,  44444, 44447, 44474,
    44477, 44744, 44747, 44774, 44777, 47444, 47447, 47474, 47477, 47744, 47747,
    47774, 47777, 74444, 74447, 74474, 74477, 74744, 74747, 74774, 74777, 77444,
    77447, 77474, 77477, 77744, 77747, 77774, 77777,
};
vector<int> l[100010];
int mark[100010];
int cnt[100010] = {};
int a[100010] = {};
int c[100010] = {};
struct item {
  int cost;
  int weight;
};
item items[3333];
int dp[100010][2];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    l[a].push_back(b);
    l[b].push_back(a);
  }
  int curMark = 1;
  for (int i = 1; i <= n; i++) {
    if (mark[i] == 0) {
      mark[i] = curMark;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (size_t u = 0; u < l[cur].size(); u++) {
          if (mark[l[cur][u]] == 0) {
            mark[l[cur][u]] = curMark;
            q.push(l[cur][u]);
          }
        }
      }
      ++curMark;
    }
  }
  for (int i = 1; i <= n; i++) {
    cnt[mark[i]]++;
  }
  memset(mark, 0, sizeof mark);
  for (int i = 1; i <= n; i++) {
    mark[cnt[i]]++;
  }
  int end = 0;
  for (int i = 1; i <= 100000; i++) {
    if (mark[i] != 0) {
      a[end] = i;
      c[end] = mark[i];
      ++end;
    }
  }
  int eitems = 0;
  for (int i = 0; i < end; i++) {
    int x;
    for (x = 1; x * 2 - 1 <= c[i]; x <<= 1) {
      item tmp = {-x, x * a[i]};
      items[eitems++] = tmp;
    }
    if (x - 1 != c[i]) {
      x = c[i] - (x - 1);
      item tmp = {-x, x * a[i]};
      items[eitems++] = tmp;
    }
  }
  memset(dp, 0x80, sizeof dp);
  dp[0][0] = 0;
  int mx = 0;
  int cur = 1;
  int prv = 0;
  int M = 0x80808080;
  for (int i = 0; i < eitems; i++) {
    for (int u = 0; u <= mx; u++) {
      dp[u][cur] = 0x80808080;
    }
    for (int u = 0; u <= mx; u++) {
      if (dp[u][prv] != 0X80808080) {
        dp[u][cur] = max(dp[u][cur], dp[u][prv]);
        dp[u + items[i].weight][cur] =
            max(dp[u + items[i].weight][cur], dp[u][prv] + items[i].cost);
        mx = max(mx, u + items[i].weight);
      }
    }
    prv ^= 1;
    cur ^= 1;
    int t = 0x80808080;
    for (int u = 0; u < 62; u++) {
      M = max(M, dp[happy[u]][prv] != 0x80808080 ? dp[happy[u]][prv] : t);
    }
  }
  cout << (M == 0x80808080 ? -1 : -M - 1) << endl;
  return 0;
}
