#include <bits/stdc++.h>
using namespace std;
bool used[200000];
vector<int> comp;
vector<int> g[200000];
void dfs(int v) {
  used[v] = true;
  comp.push_back(v);
  for (int i = 0; i < g[v].size(); i++) {
    if (!used[g[v][i]]) {
      dfs(g[v][i]);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      comp.clear();
      dfs(i);
      bool f = false;
      for (int j = 0; j < comp.size(); j++) {
        if (g[comp[j]].size() != 2) {
          f = true;
          break;
        }
      }
      if (!f) {
        cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}
