#include <bits/stdc++.h>
using namespace std;
long long c, gc;
void dfs(long long u, vector<vector<long long>>& g, vector<bool>& used,
         long long from) {
  used[u] = true;
  c++;
  gc += g[u].size() == 2;
  for (auto v : g[u])
    if (!used[v]) dfs(v, g, used, from);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> g(n + 1);
  for (long long i = 0; i < m; ++i) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<bool> used(n + 1);
  long long ans = 0;
  for (long long i = 1; i <= n; ++i)
    if (!used[i]) {
      c = 0;
      gc = 0;
      dfs(i, g, used, i);
      ans += gc == c;
    }
  cout << ans << '\n';
}
