#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e) {
  long long p = 1;
  while (e > 0) {
    if (e & 1) p = (p * b) % 1000000007;
    e = e >> 1;
    b = (b * b) % 1000000007;
  }
  return p;
}
long long a[5000], b[5000], c[5000];
bool adm[5000][5000];
int main() {
  long long n, m = 0, i, t, j, k, x, y, cnt = 0, f = 1, mn = 1000000007;
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (i = 0; i < m; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    x = a[i];
    y = b[i];
    c[a[i]]++;
    c[b[i]]++;
    adm[x][y] = adm[y][x] = 1;
  }
  for (i = 0; i < m; i++) {
    for (j = 1; j <= n; j++) {
      if (adm[a[i]][j] && adm[b[i]][j])
        mn = min(mn, c[a[i]] + c[b[i]] + c[j] - 6);
    }
  }
  if (mn == 1000000007)
    printf("%d\n", -1);
  else
    printf("%lld\n", mn);
  return 0;
}
