#include <bits/stdc++.h>
using namespace std;
vector<int> g[2 * 100000];
vector<int> c(2 * 100000, 0);
int first;
bool dfs(int v, int p, int ft = 0) {
  if (ft == 1 && c[v] == 0) {
    first = v;
    c[v]++;
    if (g[v].size() == 2) return dfs(g[v][0], v);
    return false;
  }
  if (c[v] == 0) {
    c[v]++;
    if (g[v].size() == 2)
      return g[v][0] == p ? dfs(g[v][1], v) : dfs(g[v][0], v);
  }
  if (c[v] == 1 && v == first && !ft) {
    c[v]++;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (dfs(i, -1, 1)) cnt++;
  }
  cout << cnt;
  return 0;
}
