#include <bits/stdc++.h>
using namespace std;
int ecnt;
struct Edge {
  int to, w;
  Edge *next;
} * mat[100010], edges[100010 * 2];
void link(int x, int to, int w) {
  edges[ecnt].to = to;
  edges[ecnt].w = w;
  edges[ecnt].next = mat[x];
  mat[x] = &edges[ecnt++];
}
int mark[100010], col[100010], depth;
int ans, n, m;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
void dfs(int x, int y) {
  col[x] = y;
  mark[x] = 1;
  for (Edge *p = mat[x]; p; p = p->next) {
    int to = p->to;
    if (mark[to] == 0)
      dfs(to, y + p->w);
    else
      ans = gcd(ans, abs(col[to] - y - p->w));
  }
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    link(x, y, 1);
    link(y, x, -1);
  }
  ans = 0;
  for (int i = 0; i < n; i++)
    if (!mark[i + 1]) dfs(i + 1, 0);
  if (ans == 0) ans = n;
  printf("%d\n", ans);
  return 0;
}
