#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4096;
int n, m;
vector<int> v[MAXN];
bool u[MAXN];
void read() {
  int a, b;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
}
int check(int x, int y) {
  bool flag = false;
  for (int i = 0; i < (int)v[x].size(); ++i) {
    if (v[x][i] == y) {
      flag = true;
      break;
    }
  }
  if (!flag) return 999999999;
  int best = 999999999;
  for (int i = 0; i < (int)v[x].size(); ++i) {
    for (int j = 0; j < (int)v[y].size(); ++j) {
      if (v[x][i] == v[y][j]) {
        best =
            min(best, int(v[x].size() + v[y].size() + v[v[x][i]].size()) - 6);
      }
    }
  }
  return best;
}
void solve() {
  int i, j;
  int cnt = 999999999;
  for (i = 1; i <= n; ++i) {
    for (j = i + 1; j <= n; ++j) {
      cnt = min(cnt, check(i, j));
    }
  }
  if (cnt == 999999999)
    cout << -1 << endl;
  else
    cout << cnt << endl;
}
int main() {
  read();
  solve();
  return 0;
}
