#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(int i, T X) {
  return (X & (1 << (i - 1)));
}
template <class T>
T onbit(int i, T X) {
  return (X | (1 << (i - 1)));
}
template <class T>
T offbit(int i, T X) {
  return (X | (1 << (i - 1)) - (1 << (i - 1)));
}
template <class T>
T sqr(T x) {
  return (x * x);
}
template <class T>
T cube(T x) {
  return (x * x * x);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int csx[4] = {0, 0, -1, 1};
int csy[4] = {-1, 1, 0, 0};
const int MOD = 1000000007;
const int infi = 1e9;
const int maxn = 4005;
int n, m, b[maxn + 5], d[maxn + 5][maxn + 5];
vector<int> adj[maxn + 5];
void enter() {
  int u, v;
  cin >> n >> m;
  for (typeof(n) i = 1; i <= n; i++) b[i] = 0;
  for (typeof(m) i = 1; i <= m; i++) {
    cin >> u >> v;
    b[u]++;
    b[v]++;
    adj[u].push_back(v);
    adj[v].push_back(u);
    d[u][v] = d[v][u] = 1;
  }
}
void solve() {
  int res = infi;
  for (typeof(n) i = 1; i <= n; i++) {
    int sz = adj[i].size();
    for (typeof(sz - 1) j = 0; j < sz - 1; j++)
      for (typeof(sz) k = j + 1; k < sz; k++) {
        int v1 = adj[i][j];
        int v2 = adj[i][k];
        if (d[v1][v2]) {
          res = min(res, b[i] + b[v1] + b[v2] - 6);
        }
      }
  }
  if (res == infi)
    cout << -1;
  else
    cout << res;
}
int main() {
  enter();
  solve();
  return 0;
}
