#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 100 + 10;
int color[MAXN], ans;
bool mark[MAXN];
vector<int> adj[MAXN], rev[MAXN];
int gcd(int a, int b) { return (!b ? a : gcd(b, a % b)); }
void dfs(int v, int c) {
  if (mark[v]) {
    ans = gcd(ans, abs(c - color[v]));
    return;
  }
  mark[v] = true;
  color[v] = c;
  for (int i = 0; i < int(adj[v].size()); i++) dfs(adj[v][i], c + 1);
  for (int i = 0; i < int(rev[v].size()); i++) dfs(rev[v][i], c - 1);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    rev[b].push_back(a);
  }
  for (int i = 0; i < n; i++)
    if (!mark[i]) dfs(i, 1);
  cout << (!ans ? n : ans) << endl;
  return 0;
}
