#include <bits/stdc++.h>
using namespace std;
long long n, m;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
string ds = "RLDU";
long long a, b, c, d;
bool possible(int x, int y) { return (x < n && x >= 0 && y < m && y >= 0); }
long long MOD = 0x7fffffff;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    q;
long long len = 0;
vector<long long> graph[200012];
std::vector<long long> v;
long long f;
std::vector<long long> vis(200012, 0);
std::vector<long long> dist(200012, 10000000000);
std::vector<long long> color(200012, 0);
void dfs(long long src) {
  vis[src] = 1;
  v.push_back(src);
  for (auto x : graph[src]) {
    if (!vis[x]) dfs(x);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, H, e, d, C, w, z, x, y, i;
  long long l, r, Q;
  long long count = 0;
  long long a, b, c, p, u;
  long long s, de;
  long long src, dest;
  cin >> n >> m;
  std::vector<pair<long long, long long>> edges;
  std::vector<long long> deg(200012, 0);
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
    deg[a]++;
    deg[b]++;
  }
  long long f = 0, ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      v.clear();
      dfs(i);
      f = 1;
      for (auto x : v) {
        if (deg[x] != 2) {
          f = 0;
        }
      }
      if (f) ans++;
    }
  }
  cout << ans;
  return 0;
}
