#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const int MAX = 2e5 + 5;
vector<long long> graph[MAX];
bool vis[MAX];
bool flag;
void dfs(long long node) {
  vis[node] = true;
  if (graph[node].size() != 2) flag = true;
  for (auto child : graph[node])
    if (!vis[child]) dfs(child);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, e;
  cin >> n >> e;
  for (long long i = 1; i <= e; i++) {
    long long a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      if (!flag) cnt += 1;
      flag = 0;
    }
  }
  cout << cnt << "\n";
}
