#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long N = 200005;
long long n, edgecnt, nodecnt, iscycle, start;
vector<long long> g[N], visited(N);
void dfs(long long node, long long parent) {
  visited[node] = 1;
  for (auto child : g[node]) {
    if (!visited[child]) {
      dfs(child, node);
    }
  }
  if (g[node].size() != 2) iscycle = 0;
}
void solve() {
  long long i, j, k, m, ans = 0;
  cin >> n >> m;
  for (long long i = 0; i < m; i++)
    cin >> j >> k, g[j].push_back(k), g[k].push_back(j);
  for (i = 1; i <= n; i++) {
    if (!visited[i]) {
      iscycle = 1;
      dfs(i, -1);
      if (iscycle) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1, i, j, k;
  while (t--) {
    solve();
  }
  return 0;
}
