#include <bits/stdc++.h>
using namespace std;
template <typename... T>
inline void inp(T &...args) {
  ((cin >> args), ...);
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a) in >> x;
  return in;
}
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
using graph = vector<vector<long long int>>;
long long int n, m, ok;
graph g;
vector<bool> vis;
void clearAll(long long int N) {
  N += 2;
  g.resize(N);
  vis.resize(N);
  for (long long int i = (0); ((1) > 0 ? i < (N) : i > (N)); i += (1)) {
    vis[i] = 0;
    g[i].clear();
  }
}
void dfs(long long int u) {
  vis[u] = 1;
  if (g[u].size() != 2) {
    ok = 0;
  }
  for (long long int v : g[u]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
}
void solve(int &T) {
  cin >> n >> m;
  clearAll(n);
  vector<pair<long long int, long long int>> e;
  for (long long int i = (0); ((1) > 0 ? i < (m) : i > (m)); i += (1)) {
    long long int x, y;
    cin >> x >> y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    e.push_back({x, y});
  }
  long long int ans = 0;
  for (long long int i = (1);
       (((1) <= (n + 1) ? 1 : -1) > 0 ? i < (n + 1) : i > (n + 1));
       i += ((1) <= (n + 1) ? 1 : -1)) {
    ok = 1;
    if (!vis[i]) {
      dfs(i);
      ans += ok;
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    if (0) cerr << "Case #" << i << "\n";
    solve(i);
  }
  return 0;
}
