#include <bits/stdc++.h>
using namespace std;
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = (1e5 * 2) + 20;
vector<int> cmpnt;
vector<vector<int>> gr(N);
int vis[N];
void dfs(int node) {
  if (vis[node]) {
    return;
  }
  vis[node] = 1;
  cmpnt.push_back(node);
  for (int i = 0; i < gr[node].size(); i++) {
    int nxt = gr[node][i];
    dfs(nxt);
  }
}
int main() {
  file();
  fast();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  int cnt = 0;
  vector<vector<int>> cmpontnets;
  vector<int> vis1(n + 10);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cmpnt.clear();
      dfs(i);
      cmpontnets.push_back(cmpnt);
      int sz = cmpnt.size();
      if (sz == 1) {
        continue;
      }
      int cur = cmpnt[0];
      int prev = -1;
      while (sz--) {
        if (gr[cur].size() > 2 || gr[cur].size() == 1) {
          sz = 2;
          break;
        }
        int nxt = gr[cur][0];
        if (nxt == prev) {
          nxt = gr[cur][1];
        }
        if (vis1[nxt]) {
          sz = 2;
          break;
        }
        vis1[nxt] = 1;
        prev = cur;
        cur = nxt;
      }
      if (sz == 2) {
        continue;
      }
      cnt++;
    }
  }
  cout << cnt << endl;
}
