#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long INF = (long long)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int N = 100100;
int n, m;
vector<int> g[2 * N];
int d[2 * N], used[2 * N];
bool ok = true;
void dfs(int v) {
  used[v] = 1;
  if (d[v] != 2) ok = false;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (!used[to]) {
      dfs(to);
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    d[x]++, d[y]++;
    g[x].push_back(y), g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      ok = true;
      dfs(i);
      ans += ok;
    }
  }
  cout << ans;
  return 0;
}
