#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, cnt;
bool vis[N];
int deg[N];
vector<int> cmp;
vector<int> adj[N];
void dfs(int st) {
  vis[st] = true;
  cmp.push_back(st);
  for (auto v : adj[st]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0, u, v; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      cmp.clear();
      dfs(i);
      bool ok = true;
      for (auto v : cmp) {
        ok &= deg[v] == 2;
      }
      if (ok) {
        cnt++;
      }
    }
  }
  cout << cnt << '\n';
  return 0;
}
