#include <bits/stdc++.h>
using namespace std;
const int N = 4005;
int tk[N][2];
int n, m;
bool r[N][N];
int deg[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int a, b;
  for (int i = 1; i <= n; ++i) {
    deg[i] = -2;
    ;
    for (int j = 1; j <= n; ++j) r[i][j] = false;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b;
    tk[i][0] = a;
    tk[i][1] = b;
    r[a][b] = true;
    r[b][a] = true;
    ++deg[a];
    ++deg[b];
  }
  int res = 1000000000;
  int c, d;
  for (int i = 1; i < m; ++i) {
    for (int j = i + 1; j <= m; ++j) {
      a = tk[i][0];
      b = tk[i][1];
      c = tk[j][0];
      d = tk[j][1];
      if (a == c) {
        if (r[b][d]) {
          res = min(res, deg[a] + deg[b] + deg[d]);
        }
      }
      if (b == c) {
        if (r[a][d]) {
          res = min(res, deg[a] + deg[b] + deg[d]);
        }
      }
      if (a == d) {
        if (r[b][c]) {
          res = min(res, deg[a] + deg[b] + deg[c]);
        }
      }
      if (b == d) {
        if (r[a][c]) {
          res = min(res, deg[a] + deg[b] + deg[c]);
        }
      }
    }
  }
  if (res == 1000000000)
    cout << "-1\n";
  else
    cout << res << "\n";
}
