#include <bits/stdc++.h>
using namespace std;
long long n, a[10000], b[10000], m, l[10000], ans = -1;
bool is[4001][4001];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    l[a[i]]++;
    l[b[i]]++;
    is[a[i]][b[i]] = true;
    is[b[i]][a[i]] = true;
  }
  long long x, y;
  for (long long i = 1; i <= m; i++) {
    x = a[i];
    y = b[i];
    for (long long i = 1; i <= n; i++) {
      if (is[x][i] && is[y][i] && x != i && x != y and y != i) {
        if (ans == -1) {
          ans = l[x] + l[y] + l[i] - 6;
        } else
          ans = min(ans, l[x] + l[y] + l[i] - 6);
      }
    }
  }
  cout << ans << "\n";
}
