#include <bits/stdc++.h>
using namespace std;
void dfs(vector<long long int> adj[], long long int u, vector<bool> &visited,
         vector<long long int> &p) {
  visited[u] = true;
  p.push_back(u);
  long long int i;
  for (i = 0; i < adj[u].size(); i++) {
    if (visited[adj[u][i]] == false) {
      dfs(adj, adj[u][i], visited, p);
    }
  }
}
void solve() {
  long long int n, m, i, u, v, j;
  cin >> n >> m;
  vector<long long int> adj[n];
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<vector<long long int> > cc;
  vector<bool> visited(n, false);
  for (i = 0; i < n; i++) {
    if (visited[i] == false) {
      vector<long long int> p;
      dfs(adj, i, visited, p);
      cc.push_back(p);
    }
  }
  long long int ans = 0, f;
  for (i = 0; i < cc.size(); i++) {
    f = 0;
    for (j = 0; j < cc[i].size(); j++) {
      if (adj[cc[i][j]].size() != 2) {
        f = 1;
        break;
      }
    }
    if (f == 0) ans++;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) solve();
  return 0;
}
