#include <bits/stdc++.h>
using namespace std;
long long int a[100007], b[100007], cnt[100007];
bool mark[10007][10007];
int main() {
  long long int n, ans, i, x1, x2, y1, y2, j, m;
  cin >> n >> m;
  for (i = 0; i <= n + 1; i++) {
    cnt[i] = 0;
    for (j = 0; j <= n + 1; j++) {
      mark[i][j] = 0;
    }
  }
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > b[i]) swap(a[i], b[i]);
    mark[a[i]][b[i]] = 1;
    cnt[a[i]]++;
    cnt[b[i]]++;
  }
  ans = INT_MAX;
  for (i = 0; i < m; i++) {
    for (j = i + 1; j < m; j++) {
      x1 = a[i];
      y1 = b[i];
      x2 = a[j];
      y2 = b[j];
      if (x1 == x2 && y1 != y2 && (mark[y1][y2] || mark[y2][y1])) {
        ans = min(ans, cnt[x1] + cnt[y1] + cnt[y2] - 6);
      }
    }
  }
  if (ans == INT_MAX)
    cout << "-1\n";
  else
    cout << ans << "\n";
  return 0;
}
