#include <bits/stdc++.h>
using namespace std;
long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;
char ch;
string ss = "", str = "";
map<long long, long long> mp;
set<long long> st;
bool vis[200003];
vector<long long> v[200003];
long long a[200003], b[200003];
void dfs(long long node, long long par) {
  vis[node] = 1;
  long long cc = 0;
  for (auto h : v[node]) {
    cc++;
    if (!vis[h]) dfs(h, node);
  }
  if (cc == 2) s++;
  x++;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) cin >> x >> y, v[x].push_back(y), v[y].push_back(x);
  for (i = 1; i <= n; i++) {
    x = 0;
    s = 0;
    if (!vis[i]) {
      dfs(i, -1);
      if (s == x) ct++;
    }
  }
  cout << ct;
  return 0;
}
