
import java.io.BufferedInputStream;
import java.io.IOException;

public class Main {
    static class FastScanner {
        private final BufferedInputStream in = new BufferedInputStream(System.in);

        int nextInt() throws IOException {
            int c;
            do {
                c = in.read();
            } while (c <= ' ' && c != -1);

            int num = 0;
            while (c > ' ') {
                num = num * 10 + c - '0';
                c = in.read();
            }
            return num;
        }
    }

    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        int n = fs.nextInt();
        int m = fs.nextInt();

        int[] head = new int[n + 1];
        int[] to = new int[2 * m];
        int[] next = new int[2 * m];
        int[] degree = new int[n + 1];

        java.util.Arrays.fill(head, -1);

        int edgeIndex = 0;

        for (int i = 0; i < m; i++) {
            int u = fs.nextInt();
            int v = fs.nextInt();

            to[edgeIndex] = v;
            next[edgeIndex] = head[u];
            head[u] = edgeIndex++;

            to[edgeIndex] = u;
            next[edgeIndex] = head[v];
            head[v] = edgeIndex++;

            degree[u]++;
            degree[v]++;
        }

        boolean[] visited = new boolean[n + 1];
        int[] stack = new int[n];
        int answer = 0;

        for (int i = 1; i <= n; i++) {
            if (visited[i]) {
                continue;
            }

            int top = 0;
            stack[top++] = i;
            visited[i] = true;

            boolean isCycle = true;

            while (top > 0) {
                int u = stack[--top];

                if (degree[u] != 2) {
                    isCycle = false;
                }

                for (int e = head[u]; e != -1; e = next[e]) {
                    int v = to[e];

                    if (!visited[v]) {
                        visited[v] = true;
                        stack[top++] = v;
                    }
                }
            }

            if (isCycle) {
                answer++;
            }
        }

        System.out.println(answer);
    }
}
