#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > edge;
bool adj[4001][4001];
long long cnt[4001];
long long ans = 4001 * 4001;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a][b] = true;
    adj[b][a] = true;
    edge.push_back(make_pair(a, b));
    cnt[a]++;
    cnt[b]++;
  }
  for (int i = 0; i < edge.size(); i++) {
    int a = edge[i].first;
    int b = edge[i].second;
    for (int j = 1; j <= n; j++) {
      if (j != a && j != b && adj[a][j] && adj[b][j]) {
        ans = (((((ans)) < ((cnt[a] + cnt[b] + cnt[j] - 6))))
                   ? ((ans))
                   : (((cnt[a] + cnt[b] + cnt[j] - 6))));
      }
    }
  }
  if (ans != 4001 * 4001)
    cout << ans;
  else
    cout << -1;
  return 0;
}
