#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
int tree[maxn], rd[maxn] = {0};
int vs[maxn] = {0};
int flag[maxn] = {0};
int find(int x) {
  if (tree[x] != x) tree[x] = find(tree[x]);
  return tree[x];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  iota(tree, tree + maxn, 0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    tree[find(u)] = find(v);
    rd[u] += 1;
    rd[v] += 1;
  }
  for (int i = 1; i <= n; i++) {
    vs[find(i)] += 1;
    if (rd[i] != 2) flag[find(i)] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (vs[i] > 2 && flag[i] == 0) {
      ans += 1;
    }
  cout << ans << endl;
}
