import java.util.ArrayList;
import java.util.Scanner;

public class Ornithology {

    static Scanner sc = new Scanner(System.in);

    static ArrayList<Path> paths = new ArrayList<>();

    public static void main(String[] args) {

        int n = sc.nextInt();
        int res = 0;

        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();

            for (int j = 0; j < p; j++) {
                int des = sc.nextInt();
                Path cp = new Path(i, des);
                paths.add(cp);
                for (Path op : paths) {
                    if (op.crosses(cp)) {
                        res++;
                    }
                }
            }
        }
        System.out.println(res);
    }


    static class Path {
        int start;
        int end;

        public Path(int start, int end) {
            this.start = start;
            this.end = end;
        }

        public boolean crosses(Path other) {
            int difStart = other.start - this.start;
            int difEnd = other.end - this.end;

            if (difStart < 0) {
                return difEnd >= 0;
            } else {
                return difEnd < 0;
            }
        }
    }

}
