#include <bits/stdc++.h>
using namespace std;
int c[4005], n, m, x[4005], y[4005], z;
bool e[4005][4005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= 4000; i++)
    for (int j = 1; j <= 4000; j++) e[i][j] = false;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    c[x[i]]++;
    c[y[i]]++;
    e[x[i]][y[i]] = true;
    e[y[i]][x[i]] = true;
  }
  z = 2000000000;
  for (int i = 1; i < m; i++)
    for (int j = i + 1; j <= m; j++)
      if (x[i] == x[j] && e[y[i]][y[j]])
        z = min(z, c[x[i]] + c[y[i]] + c[y[j]] - 6);
      else if (x[i] == y[j] && e[y[i]][x[j]])
        z = min(z, c[x[i]] + c[x[j]] + c[y[i]] - 6);
  if (z == 2000000000)
    cout << -1;
  else
    cout << z;
}
