#include <bits/stdc++.h>
using namespace std;
int m, n, dem = 0, res = 0, dinh[200005];
bool dd[200005];
vector<int> ke[200005];
void DFS(int u, int &dem) {
  dd[u] = 1;
  dinh[dem] = u;
  for (auto v : ke[u]) {
    if (dd[v]) continue;
    DFS(v, ++dem);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    cin >> u >> v;
    ke[u].push_back(v);
    ke[v].push_back(u);
  }
  dem = 1;
  for (int i = (1); i <= (n); ++i) {
    if (dd[i]) continue;
    DFS(i, dem);
    int cur = 0;
    for (int i = (1); i <= (dem); ++i)
      if (((int)ke[dinh[i]].size()) == 2) cur++;
    ;
    if (cur == dem) res++;
    dem = 1;
  }
  cout << res;
  return 0;
}
