#include <bits/stdc++.h>
using namespace std;
vector<int> g[4111];
int f[4111], v[4111][4111];
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    g[a].push_back(b);
    f[a]++;
    f[b]++;
    v[a][b] = v[b][a] = 1;
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      for (int k = j + 1; k < g[i].size(); k++) {
        int a = g[i][j], b = g[i][k];
        int w = f[a] + f[b] + f[i] - 6;
        if (v[a][b]) {
          if (ans == -1)
            ans = w;
          else
            ans = min(ans, w);
        }
      }
    }
  }
  cout << ans;
}
