#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> adj[N];
bool visited[N];
vector<int> comp;
void dfs(int s) {
  if (!visited[s]) {
    visited[s] = 1;
    comp.push_back(s);
    for (int i = 0; i < adj[s].size(); i++) {
      dfs(adj[s][i]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      dfs(i);
      bool ok = 1;
      for (int j = 0; j < comp.size(); j++) {
        if (adj[comp[j]].size() != 2) ok = 0;
      }
      comp.clear();
      ans += ok;
    }
  }
  cout << ans;
  return 0;
}
