1.

/**
* 10178 - Count the Faces
*
* Studiengruppe: IFB2C
* Martin Pesl
* Robert Reichart
* Elvin Uzeirovic
*
* Run Time Submission Date
* 0.068 2009-07-06 13:53:30
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

public static void main(String... args) throws IOException{
Main a = new Main();
}

Main() throws IOException{
//öffnen des Inputs und auslesen der ersten zeile welche Anzahl cases beinhaltet
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String[] given;
boolean verbose = false;

while(input.ready()){
ArrayList<Integer> edges = new ArrayList<Integer>();
ArrayList<String> nodes = new ArrayList<String>();
//ArrayList<String> old = new ArrayList<String>();
for(int i = Integer.parseInt(input.readLine().split("\\s+")[1]); i > 0; i--){

given = input.readLine().split("\\s+");

/*
if(old.contains(given[1]+given[0])){
continue;
}else{
old.add(given[0]+given[1]);
}*/

int found0 = -1;
int found1 = -1;

for(int k = 0; k < nodes.size(); k++){
if(nodes.get(k).indexOf(given[0]) >= 0){found0 = k;}
if(nodes.get(k).indexOf(given[1]) >= 0){found1 = k;}
}

if(verbose) System.out.printf("%3d: %s <-> %s%n", i, given[0], given[1]);
if(found0 < 0 && found1 < 0){
if(given[0].equals(given[1])){
nodes.add(given[0]);
}else{
nodes.add(given[0]+given[1]);
}
edges.add(1);
if(verbose) System.out.printf("new graph: %s%n", given[0]+given[1]);
}else if(found0 < 0 && found1 >= 0){
if(verbose) System.out.printf("appending %s to graph %s%n", given[0], nodes.get(found1));
nodes.set(found1, nodes.get(found1) + given[0]);
edges.set(found1, edges.get(found1) + 1);
}else if(found0 >= 0 && found1 < 0){
if(verbose) System.out.printf("appending %s to graph %s%n", given[1], nodes.get(found0));
nodes.set(found0, nodes.get(found0) + given[1]);
edges.set(found0, edges.get(found0) + 1);
}else if(found0 == found1){
if(verbose) System.out.printf("New edge added to Graph%n");
//if(!given[0].equals(given[1])){
edges.set(found0, edges.get(found0) + 1);
//}
}else {
if(verbose) System.out.printf("Connect Graph: %s + %s%n", nodes.get(found0), nodes.get(found1));
nodes.set(found0, nodes.get(found0) + nodes.get(found1));
edges.set(found0, edges.get(found0) + edges.get(found1) + 1);
nodes.remove(found1);
edges.remove(found1);
}
}
int flaechen = 1;
if(edges.size() > 0)
flaechen = 2 + edges.get(0) - nodes.get(0).length();
if(edges.size() > 1){
for(int k = 1; k < edges.size(); k++){
flaechen += 1 + edges.get(k) - nodes.get(k).length();
}
}
System.out.println(flaechen);

}
}
}