#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
vector<int> g[MAXN];
int vis[MAXN], deg[MAXN];
vector<int> ar;
void DFS(int u, int p) {
  vis[u] = true;
  ar.push_back(u);
  for (auto v : g[u]) {
    if (!vis[v]) {
      DFS(v, u);
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0, u, v; i < m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ar.clear();
      DFS(i, i);
      bool flag = false;
      for (auto x : ar) {
        if (deg[x] != 2) {
          flag = true;
          break;
        }
      }
      if (!flag) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
