#include <bits/stdc++.h>
using namespace std;
vector<int> Map[4005];
bitset<4005> Set[4005];
int solve(int a, int b, int c) {
  int ret = 0;
  ret += Set[a].count() - 2;
  ret += Set[b].count() - 2;
  ret += Set[c].count() - 2;
  return ret;
}
int main() {
  int n, m, u, v;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    Map[u].push_back(v);
    Map[v].push_back(u);
    Set[u].set(v);
    Set[v].set(u);
  }
  int ans = -1;
  for (int u = 1; u <= n; u++) {
    int len = Map[u].size();
    for (int i = 0; i < len; i++) {
      int v = Map[u][i];
      if (v < u) continue;
      int le = Map[v].size();
      for (int j = 0; j < le; j++) {
        int p = Map[v][j];
        if (p < v) continue;
        if (Set[p][u]) {
          int tmp = solve(u, v, p);
          ans = ans == -1 ? tmp : min(ans, tmp);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
