#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = N << 1;
int n, m;
int h[N], e[M], ne[M], din[N], dout[N], idx;
bool st[N];
int stk[N], top;
int ans;
void add(int a, int b) {
  din[b]++, dout[a]++, e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u) {
  st[u] = true;
  stk[++top] = u;
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    if (st[j]) continue;
    dfs(j);
  }
}
int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b), add(b, a);
  }
  for (int i = 1; i <= n; i++) {
    if (!st[i])
      dfs(i);
    else
      continue;
    bool flag = true;
    for (int j = 1; j <= top; j++)
      if (din[stk[j]] != dout[stk[j]] || din[stk[j]] != 2) {
        flag = false;
        break;
      }
    top = 0;
    if (flag) ans++;
  }
  cout << ans << endl;
  return 0;
}
