#include <bits/stdc++.h>
using namespace std;
const int N = 4e3 + 5;
int adj[N][N];
map<int, int> mp;
vector<pair<int, int>> edges;
int main() {
  ios_base::sync_with_stdio(), cout.tie(NULL), cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u][v] = adj[v][u] = 1;
    edges.push_back({u, v});
    mp[u]++;
    mp[v]++;
  }
  int ans = INT_MAX;
  for (int i = 0; i < m; i++) {
    int u = edges[i].first;
    int v = edges[i].second;
    int cur = mp[u] + mp[v];
    for (int j = 1; j <= n; j++) {
      if (adj[j][v] == 1 && adj[u][j] == 1) {
        ans = min(ans, cur + mp[j]);
      }
    }
  }
  if (ans == INT_MAX)
    cout << -1 << endl;
  else
    cout << ans - 6 << endl;
  return 0;
}
