#include <bits/stdc++.h>
using namespace std;
pair<int, int> e[5000];
bool f[5000][5000];
int c[5000];
int n, m;
int main() {
  memset(c, 0, sizeof c);
  memset(f, 0, sizeof f);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    c[x]++;
    c[y]++;
    e[i] = pair<int, int>(x, y);
    f[x][y] = true;
    f[y][x] = true;
  }
  int ans = (5 * 5000);
  for (int i = 0; i < m; i++) {
    int tmp = c[e[i].first] + c[e[i].second];
    for (int j = 1; j <= n; j++)
      if (f[e[i].first][j] && f[e[i].second][j]) {
        ans = min(ans, tmp + c[j]);
      }
  }
  if (ans == (5 * 5000))
    printf("-1");
  else
    printf("%d\n", ans - 6);
  return 0;
}
