import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
//read the question correctly (is y a vowel? what are the exact constraints?)
//look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
public class Main
{
	public static void main(String[] args)
	{
		int n=ni();
		int a[][]=new int[n][];
		for(int i=0; i<n; i++)
		{
			int te=ni();
			a[i]=nia(te);
			Arrays.sort(a[i]);
		}
		int finan=0;
		for(int i=0; i<n; i++)
		{
			for(int j=0,k=0,l=0; j<a[i].length-1; j++)
			{
				int te1=a[i][j],te2=a[i][j+1];
				while(k<a[(i-1+n)%n].length&&a[(i-1+n)%n][k]<te1)
					k++;
				while(l<a[(i+1)%n].length&&a[(i+1)%n][l]<te1)
					l++;
				int an1=0,an2=0;
				while(k<a[(i-1+n)%n].length&&a[(i-1+n)%n][k]<te2)
				{
					k++;
					an1++;
				}
				while(l<a[(i+1)%n].length&&a[(i+1)%n][l]<te2)
				{
					l++;
					an2++;
				}
				if(an1!=an2)
					finan++;
			}
		}
		pr(finan);
		System.out.print(output);
	}
	////////////////////////////////////

	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static Reader in=new Reader();
	static StringBuilder output=new StringBuilder();
	static Random rn=new Random();
	//output functions////////////////
	static void pr(Object a){output.append(a+"\n");}
	static void pr(){output.append("\n");}
	static void p(Object a){output.append(a);}
	static void pra(int[]a){for(int i:a)output.append(i+" ");output.append("\n");}
	static void pra(long[]a){for(long i:a)output.append(i+" ");output.append("\n");}
	static void pra(String[]a){for(String i:a)output.append(i+" ");output.append("\n");}
	static void pra(double[]a){for(double i:a)output.append(i+" ");output.append("\n");}
	static void sop(Object a){System.out.println(a);}
	static void flush(){System.out.println(output);output=new StringBuilder();}
	//////////////////////////////////
	//input functions/////////////////
	static int ni(){return in.nextInt();}
	static long nl(){return Long.parseLong(in.next());}
	static String ns(){return in.next();}
	static double nd(){return Double.parseDouble(in.next());}
	static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
	static int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}
	//////////////////////////////////
	//some utility functions
	static void exit(){System.exit(0);}
	static void psort(int[][] a)
	{
		Arrays.sort(a, new Comparator<int[]>()
		{
			@Override
			public int compare(int[]a,int[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(b[0]>a[0])
					return -1;
				return 0;
			}
		});
	}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static int gcd(int a, int b)
	{
		if(b==0)
			return a;
		else
			return gcd(b, a%b);
	}
	/////////////////////////
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class cf216d {

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader(InputStream in)
        {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    static boolean DEBUG = false;
    static Reader cin;
    static PrintStream out = System.out;

    public static void main(String args[]) throws Exception {
        // input
        if (args.length != 0 && "test".equals(args[0])) {
            DEBUG = true;
            String TEST = "999 2 1 1000";
            cin = new Reader(new ByteArrayInputStream(TEST.getBytes()));
        } else {
            cin = new Reader(System.in);
        }

        int n = cin.nextInt();
        int[][] bridges = new int[n][];
        for (int i = 0; i < bridges.length; i++) {
            bridges[i] = new int[cin.nextInt()];
            for (int j = 0; j < bridges[i].length; j++) bridges[i][j] = cin.nextInt();
        }

        int unstableCount = 0;
        for (int is = 0; is < bridges.length; is++) {
            int[] bs = bridges[is];
            int[] left = bridges[is == 0 ? bridges.length - 1: is - 1];
            int[] right = bridges[is == bridges.length - 1 ? 0 : is + 1];
            for (int i = 0; i < bs.length - 1; i++) {
                int cellStart = bs[i];
                int cellEnd = bs[i + 1];
                int l = (Arrays.binarySearch(left, cellStart) - Arrays.binarySearch(left, cellEnd));
                int r = (Arrays.binarySearch(right, cellStart) - Arrays.binarySearch(right, cellEnd));
                if (l != r) unstableCount += 1;
            }
        }
        out.println(unstableCount);
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class cf216d {

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader(InputStream in)
        {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    static boolean DEBUG = false;
    static Reader cin;
    static PrintStream out = System.out;

    public static void main(String args[]) throws Exception {
        // input
        if (args.length != 0 && "test".equals(args[0])) {
            DEBUG = true;
            String TEST = "7 3 1 6 7 4 3 5 2 9 2 8 1 4 3 7 6 4 3 2 5 9 3 6 3 8 3 4 2 9";
            cin = new Reader(new ByteArrayInputStream(TEST.getBytes()));
        } else {
            cin = new Reader(System.in);
        }

        int n = cin.nextInt();
        int[][] bridges = new int[n][];
        for (int i = 0; i < bridges.length; i++) {
            bridges[i] = new int[cin.nextInt()];
            for (int j = 0; j < bridges[i].length; j++) bridges[i][j] = cin.nextInt();
            Arrays.sort(bridges[i]);
        }

        int unstableCount = 0;
        for (int is = 0; is < bridges.length; is++) {
            int[] bs = bridges[is];
            int[] left = bridges[is == 0 ? bridges.length - 1: is - 1];
            int[] right = bridges[is == bridges.length - 1 ? 0 : is + 1];
            for (int i = 0; i < bs.length - 1; i++) {
                int cellStart = bs[i];
                int cellEnd = bs[i + 1];
                int l = (Arrays.binarySearch(left, cellStart) - Arrays.binarySearch(left, cellEnd));
                int r = (Arrays.binarySearch(right, cellStart) - Arrays.binarySearch(right, cellEnd));
                if (l != r) unstableCount += 1;
            }
        }
        out.println(unstableCount);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Task216D solver = new Task216D();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task216D {
        private InputReader in;
        private OutputWriter out;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.in = in;
            this.out = out;
            int n = in.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            int[][] thread = new int[n + 1][];
            TreeSet<Integer> set = new TreeSet<>();

            int cnt = 0;

            for (int i = 1; i <= n; i++) {
                int k = in.nextInt();
                thread[i] = new int[k + 1];
                thread[i][0] = k;
                for (int j = 1; j <= k; j++) {
                    int x = in.nextInt();
                    thread[i][j] = x;
                    if (!set.contains(x)) {
                        set.add(x);
                        list.add(x);
                        cnt++;
                    }
                }
                QuickSort.sort(thread[i], 1, k);
            }

            int[] pos = new int[(int) 2e5 + 1];
            Collections.sort(list);
            for (int i = 0; i < list.size(); i++) {
                pos[list.get(i)] = i + 1;
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    thread[i][j] = pos[thread[i][j]];
                }
            }

            FTSum[] ft = new FTSum[n + 1];
            ft[n] = new FTSum(MaxMin.Max(thread[n][thread[n][0]], thread[1][thread[1][0]]));
            for (int i = 1; i <= n - 1; i++) {
                ft[i] = new FTSum(MaxMin.Max(thread[i][thread[i][0]], thread[i + 1][thread[i + 1][0]]));
            }

            for (int j = 1; j <= thread[1][0]; j++) {
                ft[n].update(thread[1][j], 1);
            }
            for (int j = 1; j <= thread[n][0]; j++) {
                ft[n].update(thread[n][j], 1);
            }

            for (int i = 1; i < n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    ft[i].update(thread[i][j], 1);
                }
                for (int j = 1; j <= thread[i + 1][0]; j++) {
                    ft[i].update(thread[i + 1][j], 1);
                }
            }
            int ans = 0;
            for (int j = 2; j <= thread[1][0]; j++) {
                if (ft[1].getSum(thread[1][j - 1], thread[1][j]) != ft[n].getSum(thread[1][j - 1], thread[1][j]))
                    ans++;
            }
            out.println(ans);
            for (int i = 2; i <= n; i++) {
                for (int j = 2; j <= thread[i][0]; j++) {
                    if (ft[i - 1].getSum(thread[i][j - 1], thread[i][j]) != ft[i].getSum(thread[i][j - 1], thread[i][j]))
                        ans++;
                }
                out.println(ans);

            }
            out.println(ans);
        }

    }

    static class QuickSort {
        public static void sort(int[] list, int lowIndex, int highIndex) {
            ArrayUtils.shuffleArray(list, lowIndex, highIndex);
            Arrays.sort(list, lowIndex, highIndex + 1);
        }

    }

    static class OutputWriter {
        private final PrintWriter out;

        public OutputWriter(OutputStream outputStream) {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.out = new PrintWriter(writer);
        }

        public void close() {
            out.close();
        }

        public void println(int i) {
            out.println(i);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class ArrayUtils {
        public static void shuffleArray(int[] array, int stIndex, int enIndex) {
            for (int i = enIndex; i > stIndex; i--) {
                int index = (int) OneNumberGen.genInt(stIndex, i - 1);
                if (index != i) {
                    array[index] ^= array[i];
                    array[i] ^= array[index];
                    array[index] ^= array[i];
                }
            }
        }

    }

    static class OneNumberGen {
        private static long genI(long min, long max) {
            return ThreadLocalRandom.current().nextLong(min, max + 1);
        }

        public static long genInt(long min, long max) {
            if (min >= 0)
                return (genI(min, max));
            else if (max >= 0) {
                double ratio = (double) Math.abs(min) / (Math.abs(min) + max);
                ratio *= 1000000000000000000D;
                double prob = (double) (OneNumberGen.genInt(1, 1000000000000000000L));
                if (Double.compare(ratio, prob) > 0) {
                    return -(genI(0, -min));
                } else {
                    return (genI(0, max));
                }
            } else
                return -(OneNumberGen.genI(-min, -max));
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Max(T x, T y) {
            T max = x;
            if (y.compareTo(max) > 0) max = y;
            return max;
        }

    }

    static class FTSum {
        private int n;
        private int[] sum;

        public FTSum(int n) {
            sum = new int[n + 1];
            this.n = n;
        }

        public void update(int pos, int val) {
            while (pos <= n) {
                sum[pos] += val;
                pos += pos & -pos;
            }
        }

        public int getSum(int pos) {
            int ans = 0;
            while (pos != 0) {
                ans += sum[pos];
                pos -= pos & -pos;
            }
            return ans;
        }

        public int getSum(int l, int r) {
            return getSum(r) - getSum(l - 1);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Task216D solver = new Task216D();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task216D {
        private InputReader in;
        private OutputWriter out;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.in = in;
            this.out = out;
            int n = in.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            int[][] thread = new int[n + 1][];
            TreeSet<Integer> set = new TreeSet<>();

            int cnt = 0;

            for (int i = 1; i <= n; i++) {
                int k = in.nextInt();
                thread[i] = new int[k + 1];
                thread[i][0] = k;
                for (int j = 1; j <= k; j++) {
                    int x = in.nextInt();
                    thread[i][j] = x;
                    if (!set.contains(x)) {
                        set.add(x);
                        list.add(x);
                        cnt++;
                    }
                }
                QuickSort.sort(thread[i], 1, k);
            }

            int[] pos = new int[(int) 2e5 + 1];
            Collections.sort(list);
            for (int i = 0; i < list.size(); i++) {
                pos[list.get(i)] = i + 1;
            }

            set.clear();
            list.clear();

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    thread[i][j] = pos[thread[i][j]];
                }
            }

            FTSum[] ft = new FTSum[n + 1];
            ft[n] = new FTSum(MaxMin.Max(thread[n][thread[n][0]], thread[1][thread[1][0]]));
            for (int i = 1; i <= n - 1; i++) {
                ft[i] = new FTSum(MaxMin.Max(thread[i][thread[i][0]], thread[i + 1][thread[i + 1][0]]));
            }

            for (int j = 1; j <= thread[1][0]; j++) {
                ft[n].update(thread[1][j], 1);
            }
            for (int j = 1; j <= thread[n][0]; j++) {
                ft[n].update(thread[n][j], 1);
            }

            for (int i = 1; i < n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    ft[i].update(thread[i][j], 1);
                }
                for (int j = 1; j <= thread[i + 1][0]; j++) {
                    ft[i].update(thread[i + 1][j], 1);
                }
            }
            int ans = 0;
            for (int j = 2; j <= thread[1][0]; j++) {
                if (ft[1].getSum(thread[1][j - 1], thread[1][j]) != ft[n].getSum(thread[1][j - 1], thread[1][j]))
                    ans++;
            }
            for (int i = 2; i <= n; i++) {
                for (int j = 2; j <= thread[i][0]; j++) {
                    if (ft[i - 1].getSum(thread[i][j - 1], thread[i][j]) != ft[i].getSum(thread[i][j - 1], thread[i][j]))
                        ans++;
                }
            }
            out.println(ans);
        }

    }

    static class QuickSort {
        public static void sort(int[] list, int lowIndex, int highIndex) {
            ArrayUtils.shuffleArray(list, lowIndex, highIndex);
            Arrays.sort(list, lowIndex, highIndex + 1);
        }

    }

    static class OutputWriter {
        private final PrintWriter out;

        public OutputWriter(OutputStream outputStream) {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.out = new PrintWriter(writer);
        }

        public void close() {
            out.close();
        }

        public void println(int i) {
            out.println(i);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class FTSum {
        private int n;
        private int[] sum;

        public FTSum(int n) {
            sum = new int[n + 1];
            this.n = n;
        }

        public void update(int pos, int val) {
            while (pos <= n) {
                sum[pos] += val;
                pos += pos & -pos;
            }
        }

        public int getSum(int pos) {
            int ans = 0;
            while (pos != 0) {
                ans += sum[pos];
                pos -= pos & -pos;
            }
            return ans;
        }

        public int getSum(int l, int r) {
            return getSum(r) - getSum(l - 1);
        }

    }

    static class OneNumberGen {
        private static long genI(long min, long max) {
            return ThreadLocalRandom.current().nextLong(min, max + 1);
        }

        public static long genInt(long min, long max) {
            if (min >= 0)
                return (genI(min, max));
            else if (max >= 0) {
                double ratio = (double) Math.abs(min) / (Math.abs(min) + max);
                ratio *= 1000000000000000000D;
                double prob = (double) (OneNumberGen.genInt(1, 1000000000000000000L));
                if (Double.compare(ratio, prob) > 0) {
                    return -(genI(0, -min));
                } else {
                    return (genI(0, max));
                }
            } else
                return -(OneNumberGen.genI(-min, -max));
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Max(T x, T y) {
            T max = x;
            if (y.compareTo(max) > 0) max = y;
            return max;
        }

    }

    static class ArrayUtils {
        public static void shuffleArray(int[] array, int stIndex, int enIndex) {
            for (int i = enIndex; i > stIndex; i--) {
                int index = (int) OneNumberGen.genInt(stIndex, i - 1);
                if (index != i) {
                    array[index] ^= array[i];
                    array[i] ^= array[index];
                    array[index] ^= array[i];
                }
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Task216D solver = new Task216D();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task216D {
        private InputReader in;
        private OutputWriter out;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.in = in;
            this.out = out;
            int n = in.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            int[][] thread = new int[n + 1][];
            TreeSet<Integer> set = new TreeSet<>();

            int cnt = 0;

            for (int i = 1; i <= n; i++) {
                int k = in.nextInt();
                thread[i] = new int[k + 1];
                thread[i][0] = k;
                for (int j = 1; j <= k; j++) {
                    int x = in.nextInt();
                    thread[i][j] = x;
                    if (!set.contains(x)) {
                        set.add(x);
                        list.add(x);
                        cnt++;
                    }
                }
                QuickSort.sort(thread[i], 1, k);
            }

            int[] pos = new int[(int) 1e5 + 1];
            Collections.sort(list);
            for (int i = 0; i < list.size(); i++) {
                pos[list.get(i)] = i + 1;
            }

            set.clear();
            list.clear();

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    thread[i][j] = pos[thread[i][j]];
                }
            }

            FTSum[] ft = new FTSum[n + 1];
            ft[n] = new FTSum(MaxMin.Max(thread[n][thread[n][0]], thread[1][thread[1][0]]));

            for (int j = 1; j <= thread[1][0]; j++) {
                ft[n].update(thread[1][j], 1);
            }
            for (int j = 1; j <= thread[n][0]; j++) {
                ft[n].update(thread[n][j], 1);
            }
            int ans = 0;

            for (int i = 1; i < n; i++) {
                ft[i] = new FTSum(MaxMin.Max(thread[i][thread[i][0]], thread[i + 1][thread[i + 1][0]]));
                for (int j = 1; j <= thread[i][0]; j++) {
                    ft[i].update(thread[i][j], 1);
                }
                for (int j = 1; j <= thread[i + 1][0]; j++) {
                    ft[i].update(thread[i + 1][j], 1);
                }
                if (i > 1) {
                    for (int j = 2; j <= thread[i][0]; j++) {
                        if (ft[i - 1].getSum(thread[i][j - 1], thread[i][j]) != ft[i].getSum(thread[i][j - 1], thread[i][j]))
                            ans++;
                    }
                    if (i > 2) ft[i - 1].clear();
                }
            }

            for (int j = 2; j <= thread[1][0]; j++) {
                if (ft[1].getSum(thread[1][j - 1], thread[1][j]) != ft[n].getSum(thread[1][j - 1], thread[1][j]))
                    ans++;
            }
            for (int j = 2; j <= thread[n][0]; j++) {
                if (ft[n - 1].getSum(thread[n][j - 1], thread[n][j]) != ft[n].getSum(thread[n][j - 1], thread[n][j]))
                    ans++;
            }
//        for (int i = 2; i <= n; i++) {
//            for (int j = 2; j <= thread[i][0]; j++) {
//                if (ft[i - 1].getSum(thread[i][j - 1], thread[i][j]) != ft[i].getSum(thread[i][j - 1], thread[i][j]))
//                    ans++;
//            }
//        }
            out.println(ans);
        }

    }

    static class QuickSort {
        public static void sort(int[] list, int lowIndex, int highIndex) {
            ArrayUtils.shuffleArray(list, lowIndex, highIndex);
            Arrays.sort(list, lowIndex, highIndex + 1);
        }

    }

    static class OutputWriter {
        private final PrintWriter out;

        public OutputWriter(OutputStream outputStream) {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.out = new PrintWriter(writer);
        }

        public void close() {
            out.close();
        }

        public void println(int i) {
            out.println(i);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class FTSum {
        private int n;
        private int[] sum;

        public FTSum(int n) {
            sum = new int[n + 1];
            this.n = n;
        }

        public void update(int pos, int val) {
            while (pos <= n) {
                sum[pos] += val;
                pos += pos & -pos;
            }
        }

        public int getSum(int pos) {
            int ans = 0;
            while (pos != 0) {
                ans += sum[pos];
                pos -= pos & -pos;
            }
            return ans;
        }

        public int getSum(int l, int r) {
            return getSum(r) - getSum(l - 1);
        }

        public void clear() {
            sum = null;
            n = 0;
        }

    }

    static class ArrayUtils {
        public static void shuffleArray(int[] array, int stIndex, int enIndex) {
            for (int i = enIndex; i > stIndex; i--) {
                int index = (int) OneNumberGen.genInt(stIndex, i - 1);
                if (index != i) {
                    array[index] ^= array[i];
                    array[i] ^= array[index];
                    array[index] ^= array[i];
                }
            }
        }

    }

    static class OneNumberGen {
        private static long genI(long min, long max) {
            return ThreadLocalRandom.current().nextLong(min, max + 1);
        }

        public static long genInt(long min, long max) {
            if (min >= 0)
                return (genI(min, max));
            else if (max >= 0) {
                double ratio = (double) Math.abs(min) / (Math.abs(min) + max);
                ratio *= 1000000000000000000D;
                double prob = (double) (OneNumberGen.genInt(1, 1000000000000000000L));
                if (Double.compare(ratio, prob) > 0) {
                    return -(genI(0, -min));
                } else {
                    return (genI(0, max));
                }
            } else
                return -(OneNumberGen.genI(-min, -max));
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Max(T x, T y) {
            T max = x;
            if (y.compareTo(max) > 0) max = y;
            return max;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Task216D solver = new Task216D();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task216D {
        private InputReader in;
        private OutputWriter out;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.in = in;
            this.out = out;
            int n = in.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            int[][] thread = new int[n + 1][];
            TreeSet<Integer> set = new TreeSet<>();

            int cnt = 0;

            for (int i = 1; i <= n; i++) {
                int k = in.nextInt();
                thread[i] = new int[k + 1];
                thread[i][0] = k;
                for (int j = 1; j <= k; j++) {
                    int x = in.nextInt();
                    thread[i][j] = x;
                    if (!set.contains(x)) {
                        set.add(x);
                        list.add(x);
                        cnt++;
                    }
                }
                QuickSort.sort(thread[i], 1, k);
            }

            int[] pos = new int[(int) 2e5 + 1];
            Collections.sort(list);
            for (int i = 0; i < list.size(); i++) {
                pos[list.get(i)] = i + 1;
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    thread[i][j] = pos[thread[i][j]];
                }
            }

            FTSum[] ft = new FTSum[n + 1];
            ft[n] = new FTSum(MaxMin.Max(thread[n][thread[n][0]], thread[1][thread[1][0]]));
            for (int i = 1; i <= n - 1; i++) {
                ft[i] = new FTSum(MaxMin.Max(thread[i][thread[i][0]], thread[i + 1][thread[i + 1][0]]));
            }

            for (int j = 1; j <= thread[1][0]; j++) {
                ft[n].update(thread[1][j], 1);
            }
            for (int j = 1; j <= thread[n][0]; j++) {
                ft[n].update(thread[n][j], 1);
            }

            for (int i = 1; i < n; i++) {
                for (int j = 1; j <= thread[i][0]; j++) {
                    ft[i].update(thread[i][j], 1);
                }
                for (int j = 1; j <= thread[i + 1][0]; j++) {
                    ft[i].update(thread[i + 1][j], 1);
                }
            }
            int ans = 0;
            for (int j = 2; j <= thread[1][0]; j++) {
                if (ft[1].getSum(thread[1][j - 1], thread[1][j]) != ft[n].getSum(thread[1][j - 1], thread[1][j]))
                    ans++;
            }
            for (int i = 2; i <= n; i++) {
                for (int j = 2; j <= thread[i][0]; j++) {
                    if (ft[i - 1].getSum(thread[i][j - 1], thread[i][j]) != ft[i].getSum(thread[i][j - 1], thread[i][j]))
                        ans++;
                }
            }
            out.println(ans);
        }

    }

    static class QuickSort {
        public static void sort(int[] list, int lowIndex, int highIndex) {
            ArrayUtils.shuffleArray(list, lowIndex, highIndex);
            Arrays.sort(list, lowIndex, highIndex + 1);
        }

    }

    static class OutputWriter {
        private final PrintWriter out;

        public OutputWriter(OutputStream outputStream) {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.out = new PrintWriter(writer);
        }

        public void close() {
            out.close();
        }

        public void println(int i) {
            out.println(i);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class ArrayUtils {
        public static void shuffleArray(int[] array, int stIndex, int enIndex) {
            for (int i = enIndex; i > stIndex; i--) {
                int index = (int) OneNumberGen.genInt(stIndex, i - 1);
                if (index != i) {
                    array[index] ^= array[i];
                    array[i] ^= array[index];
                    array[index] ^= array[i];
                }
            }
        }

    }

    static class OneNumberGen {
        private static long genI(long min, long max) {
            return ThreadLocalRandom.current().nextLong(min, max + 1);
        }

        public static long genInt(long min, long max) {
            if (min >= 0)
                return (genI(min, max));
            else if (max >= 0) {
                double ratio = (double) Math.abs(min) / (Math.abs(min) + max);
                ratio *= 1000000000000000000D;
                double prob = (double) (OneNumberGen.genInt(1, 1000000000000000000L));
                if (Double.compare(ratio, prob) > 0) {
                    return -(genI(0, -min));
                } else {
                    return (genI(0, max));
                }
            } else
                return -(OneNumberGen.genI(-min, -max));
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Max(T x, T y) {
            T max = x;
            if (y.compareTo(max) > 0) max = y;
            return max;
        }

    }

    static class FTSum {
        private int n;
        private int[] sum;

        public FTSum(int n) {
            sum = new int[n + 1];
            this.n = n;
        }

        public void update(int pos, int val) {
            while (pos <= n) {
                sum[pos] += val;
                pos += pos & -pos;
            }
        }

        public int getSum(int pos) {
            int ans = 0;
            while (pos != 0) {
                ans += sum[pos];
                pos -= pos & -pos;
            }
            return ans;
        }

        public int getSum(int l, int r) {
            return getSum(r) - getSum(l - 1);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<TreeMap<Integer, Integer>> p = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                TreeMap<Integer, Integer> pCur = new TreeMap<>();
                ArrayList<Integer> arrCur = new ArrayList<>();
                int k = in.nextInt();
                for (int j = 0; j < k; j++) {
                    arrCur.add(in.nextInt());
                }
                arrCur.sort(Integer::compareTo);
                int ind = 1;
                for (int j : arrCur) {
                    pCur.put(j, ind++);
                }
                p.add(pCur);
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                int left = (n + i - 1) % n;
                int right = (i + 1) % n;
                for (int cur : p.get(i).keySet()) {
                    Integer roof = p.get(i).higherKey(cur);
                    if (roof == null) continue;
                    int leftNei = 0;
                    Integer leftBigger = p.get(left).higherKey(cur - 1);
                    Integer leftSmaller = p.get(left).lowerKey(roof + 1);
                    if (leftBigger != null && leftSmaller != null && p.get(left).get(leftBigger) <= p.get(left).get(leftSmaller)) {
                        leftNei = p.get(left).get(leftSmaller) - p.get(left).get(leftBigger) + 1;
                    }
                    int rightNei = 0;
                    Integer rightBigger = p.get(right).higherKey(cur - 1);
                    Integer rightSmaller = p.get(right).lowerKey(roof + 1);
                    if (rightBigger != null && rightSmaller != null && p.get(right).get(rightBigger) <= p.get(right).get(rightSmaller)) {
                        rightNei = p.get(right).get(rightSmaller) - p.get(right).get(rightBigger) + 1;
                    }
                    if (rightNei != leftNei) {
                        ans++;
                    }
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static int solve(int[] a,int[]b ,int[]c)
	{
		int ans = 0;
		int i = 0 , k = 0;
		for(int j = 1;j<b.length;j++)
		{
			int l = b[j-1] , r = b[j];
			while(i<a.length && a[i]<l)++i;
			while(k<c.length && c[k]<l)++k;
			int upper = 0 , lower = 0;
			for(;i<a.length && a[i]>=l && a[i]<=r; ++i,++upper);
			for(;k<c.length && c[k]>=l && c[k]<=r; ++k,++lower);
			if(upper!=lower)++ans;
		}
		return ans;
	}

	public static void main(String[] args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][];
		for (int i = 0; i < a.length; i++) {
			int s = sc.nextInt();
			a[i] = new int[s];
			for (int j = 0; j < a[i].length; j++)
				a[i][j] = sc.nextInt();
			Arrays.sort(a[i]);
		}
		int ans = solve(a[n-1], a[0],a[1]) + solve(a[n-2], a[n-1], a[0]);
		for (int i = 1; i < a.length-1; i++)
			ans += solve(a[i-1], a[i], a[i+1]);
		System.out.println(ans);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {br = new BufferedReader(new InputStreamReader(s));}
		public Scanner(String file) throws FileNotFoundException {br = new BufferedReader(new FileReader(file));}
		public String next() throws IOException {while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
		public int[] nexIntArray() throws Throwable {
			st = new StringTokenizer(br.readLine());
			int[] a = new int[st.countTokens()];
			for (int i = 0; i < a.length; i++)a[i] = nextInt();
			return a;
		}
		public boolean ready() throws IOException {return br.ready();}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class D {

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();
        int[][] a = new int[n][];
        for (int i = 0; i < n; i++) {
            int k = in.nextInt();
            a[i] = new int[k];
            for (int j = 0; j < k; j++)
                a[i][j] = in.nextInt();
            Arrays.sort(a[i]);
        }
        int cnt = 0;
        int[] left;
        int[] right;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < a[i].length - 1; j++) {
                left = a[(i + 1) % n];
                right = a[((i - 1) % n + n) % n];
                if (getNum(left, a[i][j], a[i][j + 1]) != getNum(right,
                        a[i][j], a[i][j + 1]))
                    cnt++;
            }
        }
        System.out.println(cnt);
    }

    public static int getNum(int[] a, int l, int r) {
        int lo = 0;
        int hi = a.length - 1;
        int mid;
        while (lo < hi) {
            mid = (lo + hi) / 2;
            if (a[mid] > l)
                hi = mid;
            else
                lo = mid + 1;
        }
        int a1 = lo;
        lo = 0;
        hi = a.length - 1;
        while (lo < hi) {
            mid = (lo + hi + 1) / 2;
            if (a[mid] < r)
                lo = mid;
            else
                hi = mid - 1;
        }
        int a2 = lo;
        int ans = a2 - a1 + 1;
        if (ans < 0)
            ans = 0;
        return ans;
    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer st;

        public InputReader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer(in.readLine());
        }

        public String next() throws IOException {
            while (!st.hasMoreElements())
                st = new StringTokenizer(in.readLine());
            return st.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class D {

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();
        int[][] a = new int[n][];
        for (int i = 0; i < n; i++) {
            int k = in.nextInt();
            a[i] = new int[k];
            for (int j = 0; j < k; j++)
                a[i][j] = in.nextInt();
            Arrays.sort(a[i]);
        }
        int cnt = 0;
        int[] left;
        int[] right;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < a[i].length - 1; j++) {
                left = a[(i + 1) % n];
                right = a[((i - 1) % n + n) % n];
                if (getNum(left, a[i][j], a[i][j + 1]) != getNum(right,
                        a[i][j], a[i][j + 1]))
                    cnt++;
            }
        }
        System.out.println(cnt);
    }

    public static int getNum(int[] a, int l, int r) {
        int lo = 0;
        int hi = a.length - 1;
        int mid;
        while (lo < hi) {
            mid = (lo + hi) / 2;
            if (a[mid] > l)
                hi = mid;
            else
                lo = mid + 1;
        }
        int a1 = lo;
        lo = 0;
        hi = a.length - 1;
        while (lo < hi) {
            mid = (lo + hi + 1) / 2;
            if (a[mid] < r)
                lo = mid;
            else
                hi = mid - 1;
        }
        int a2 = lo;
        return a2 - a1 + 1;
    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer st;

        public InputReader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer(in.readLine());
        }

        public String next() throws IOException {
            while (!st.hasMoreElements())
                st = new StringTokenizer(in.readLine());
            return st.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class D {

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        int n = in.nextInt();
        int[][] a = new int[n][];
        for (int i = 0; i < n; i++) {
            int k = in.nextInt();
            a[i] = new int[k];
            for (int j = 0; j < k; j++)
                a[i][j] = in.nextInt();
            Arrays.sort(a[i]);
        }
        int cnt = 0;
        int[] left;
        int[] right;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < a[i].length - 1; j++) {
                left = a[(i + 1) % n];
                right = a[((i - 1) % n + n) % n];
                if (getNum(left, a[i][j], a[i][j + 1]) != getNum(right,
                        a[i][j], a[i][j + 1]))
                    cnt++;
            }
        }
        System.out.println(cnt);
    }

    public static int getNum(int[] a, int l, int r) {
        int lo = 0;
        int hi = a.length - 1;
        int mid;
        while (lo < hi) {
            mid = (lo + hi) / 2;
            if (a[mid] > l)
                hi = mid;
            else
                lo = mid + 1;
        }
        int a1 = lo;
        if (!(a[a1] > l) || !(a[a1] < r))
            return 0;
        lo = 0;
        hi = a.length - 1;
        while (lo < hi) {
            mid = (lo + hi + 1) / 2;
            if (a[mid] < r)
                lo = mid;
            else
                hi = mid - 1;
        }
        int a2 = lo;
        if (!(a[a2] > l) || !(a[a2] < r))
            return 0;
        int ans = a2 - a1 + 1;
        if (ans < 0)
            ans = 0;
        return ans;
    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer st;

        public InputReader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer(in.readLine());
        }

        public String next() throws IOException {
            while (!st.hasMoreElements())
                st = new StringTokenizer(in.readLine());
            return st.nextToken();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}


import java.io.*;
import java.util.*;

public class D implements Runnable {
	private MyScanner in;
	private PrintWriter out;

	private void solve() {
		int n = in.nextInt();
		List<List<Integer>> dist = new ArrayList<List<Integer>>(n);
		for (int i = 0; i < n; ++i) {
			int k = in.nextInt();
			List<Integer> cur = new ArrayList<Integer>(k);
			for (int j = 0; j < k; ++j) {
				cur.add(in.nextInt());
			}
			Collections.sort(cur);
			dist.add(cur);
		}
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			int before = (i + n - 1) % n, after = (i + 1) % n;
			int pBefore = 0, pAfter = 0;
			List<Integer> l = dist.get(i), lBefore = dist.get(before), lAfter = dist
					.get(after);
			for (int p = 0; p < l.size() - 1; ++p) {
				int from = l.get(p), to = l.get(p + 1);
				int left = 0;
				while (pBefore < lBefore.size()) {
					int cur = lBefore.get(pBefore);
					if (cur < from) {
						++pBefore;
						continue;
					}
					if (cur > to) {
						break;
					}
					++left;
					++pBefore;
				}
				int right = 0;
				while (pAfter < lAfter.size()) {
					int cur = lAfter.get(pAfter);
					if (cur < from) {
						++pAfter;
						continue;
					}
					if (cur > to) {
						break;
					}
					++right;
					++pAfter;
				}
				if (left != right) {
					// System.err.println(i + " " + p);
					++ans;
				}
			}
		}
		out.println(ans);
	}

	@Override
	public void run() {
		in = new MyScanner();
		out = new PrintWriter(System.out);
		solve();
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new D().run();
	}

	class MyScanner {
		private BufferedReader br;
		private StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public MyScanner(String fileName) {
			try {
				br = new BufferedReader(new FileReader(fileName));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		public boolean hasNext() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String s = br.readLine();
					if (s == null) {
						return false;
					}
					st = new StringTokenizer(s);
				} catch (IOException e) {
					e.printStackTrace();
					return false;
				}
			}
			return true;
		}

		private String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String s = br.readLine();
					if (s == null) {
						return null;
					}
					st = new StringTokenizer(s);
				} catch (IOException e) {
					e.printStackTrace();
					return null;
				}
			}
			return st.nextToken();
		}

		public String nextLine() {
			try {
				st = null;
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
				return null;
			}
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.util.Arrays;

public class D {

    class Scanner {
        int nextInt() {
            try {
                int c = System.in.read();
                while (c != '-' && (c < '0' || '9' < c))
                    c = System.in.read();
                if (c == '-') return -nextInt();
                int res = 0;
                do {
                    res *= 10;
                    res += c - '0';
                    c = System.in.read();
                } while ('0' <= c && c <= '9');
                return res;
            } catch (Exception e) {
                return -1;
            }
        }
    }

    int upperBound(int[] a, int x){
        int left = 0;
        int right = a.length;
        while(true){
            if(right-left<=1){
                return a[left]>x?left:right;
            }
            else{
                int m = (left+right)/2;
                if(a[m]>x){
                    right = m;
                }
                else{
                    left = m;
                }
            }
        }
    }
    int lowerBound(int[] a, int x){
        int left = 0;
        int right = a.length;
        while(true){
            if(right-left<=1){
                return a[left]>=x?left:right;
            }
            else{
                int m = (left+right)/2;
                if(a[m]>=x){
                    right = m;
                }
                else{
                    left = m;
                }
            }
        }
    }

    void run(){
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[][] web = new int[n][];
        for(int i=0;i<n;i++){
            int k = sc.nextInt();
            web[i] = new int[k];
            for(int j=0;j<k;j++)web[i][j]=sc.nextInt();
            Arrays.sort(web[i]);
        }
        int res = 0;
        for(int i=0;i<n;i++){
            int a = (i-1+n)%n, b = (i+1)%n;
            int size = web[i].length;
            for(int j=0;j+1<size;j++){
                int left = upperBound(web[a], web[i][j+1])-lowerBound(web[a], web[i][j]);
                int right = upperBound(web[b], web[i][j+1])-lowerBound(web[b], web[i][j]);
                if(left!=right)res++;
            }
        }
        System.out.println(res);
    }

    void debug(Object...o){
        System.out.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new D().run();
    }
}


import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;

    private int nextInt() throws Exception{
	if (str == null || !str.hasMoreElements()){
	    str = new StringTokenizer(in.readLine());
	}
	return Integer.parseInt(str.nextToken());
    }

    public void run() throws Exception{
	in = new BufferedReader(new InputStreamReader(System.in));
	int n = nextInt();
	int g[][] = new int[n][];
	for(int i=0;i<n;i++){
	    int k = nextInt();
	    g[i] = new int[k];
	    for(int j=0;j<k;j++)
		g[i][j] = nextInt();
	}
	for(int i=0;i<n;i++)
	    Arrays.sort(g[i]);

	int ret = 0;
	for(int i=0;i<n;i++){
	    int next = (i+1)%n;
	    int prev = ((i-1)%n + n)%n;

	    int leftidx = 0;
	    int rightidx = 0;

	    for(int j=0;j<g[i].length;j++){
		int right = 0, left = 0;
		int val = g[i][j];

		while(leftidx < g[prev].length && g[prev][leftidx] < val){
		    leftidx++;
		    left++;
		}

		while(rightidx < g[next].length && g[next][rightidx] < val){
		    rightidx++;
		    right++;
		}

		if (j!=0 && left != right){
		    ret++;
		}
	    }
	}
	System.out.println(ret);
    }

    public static void main(String args[]) throws Exception{
	new Main().run();
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;

public class D
{
	BufferedReader in;
	PrintStream out;
	StringTokenizer tok;
	public D() throws NumberFormatException, IOException
	{
		in = new BufferedReader(new InputStreamReader(System.in));
		//in = new BufferedReader(new FileReader("in.txt"));
		out = System.out;
		run();
	}
	int bs(int[] a, int x)
	{
		int l = 0;
		int h = a.length-1;
		while(l<=h)
		{
			int m = (l+h)/2;
			if(a[m] < x)l = m+1;
			else h = m-1;
		}
		return l;
	}
	boolean isbad(int i,int b1, int b2, int n)
	{
		int ans1 = 0, ans2 = 0;
		int index = bs(bridges[(i-1+n)%n], b1);
		while(index <bridges[(i-1+n)%n].length && bridges[(i-1+n)%n][index]>b1 && bridges[(i-1+n)%n][index]<b2)
		{
			index++;
			ans1++;
		}
		index = bs(bridges[(i+1)%n], b1);
		while(index < bridges[(i+1)%n].length && bridges[(i+1)%n][index]>b1 && bridges[(i+1)%n][index]<b2)
		{
			index++;
			ans2++;
		}
		return ans1 != ans2;
	}
	int[][] bridges;
	void run() throws NumberFormatException, IOException
	{
		int n = nextInt();
		bridges = new int[n][];
		for(int i = 0; i < n; i++)
		{
			int k = nextInt();
			bridges[i] = new int[k];
			for(int j = 0; j < k; j++)
				bridges[i][j] = nextInt();
			Arrays.sort(bridges[i]);
		}
		int ans = 0;
		for(int i = 0; i < n; i++)
		{
			for(int j = 1; j < bridges[i].length; j++)
				if(isbad(i,bridges[i][j-1],bridges[i][j],n))ans++;
		}
		out.println(ans);
	}
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		new D();
	}
	String nextToken() throws IOException
	{
		if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
		return tok.nextToken();
	}
	int nextInt() throws NumberFormatException, IOException
	{
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws NumberFormatException, IOException
	{
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws NumberFormatException, IOException
	{
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;

public class D {

    static StreamTokenizer st;
    public static void main(String[] args) throws IOException{
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        ArrayList<Integer>[]segments = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            int k = nextInt();
            segments[i] = new ArrayList<Integer>();
            for (int j = 1; j <= k; j++) {
                segments[i].add(nextInt());
            }
        }
        for (int i = 0; i < n; i++) {
            Collections.sort(segments[i]);
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int left = (i-1+n) % n, right = (i+1) % n;
            for (int j = 0; j < segments[i].size()-1; j++) {
                int L1 = segments[i].get(j), L2 = segments[i].get(j+1);
                int k1 = Collections.binarySearch(segments[left], L1);
                if (k1 < 0)
                    k1 = Math.abs(k1)-2;
                int k2 = Collections.binarySearch(segments[left], L2);
                if (k2 < 0)
                    k2 = Math.abs(k2)-2;
                int k3 = Collections.binarySearch(segments[right], L1);
                if (k3 < 0)
                    k3 = Math.abs(k3)-2;
                int k4 = Collections.binarySearch(segments[right], L2);
                if (k4 < 0)
                    k4 = Math.abs(k4)-2;
                if (k2-k1 != k4-k3)
                    ans++;
            }
        }
        pw.print(ans);
        pw.close();
    }

    private static int nextInt() throws IOException{
        st.nextToken();
        return (int) st.nval;
    }

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;

public class D {

    static StreamTokenizer st;
    public static void main(String[] args) throws IOException{
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        ArrayList<Integer>[]segments = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            int k = nextInt();
            segments[i] = new ArrayList<Integer>();
            for (int j = 1; j <= k; j++) {
                segments[i].add(nextInt());
            }
        }
        for (int i = 0; i < n; i++) {
            Collections.sort(segments[i]);
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int left = (i-1+n) % n, right = (i+1) % n;
            for (int j = 0; j < segments[i].size()-1; j++) {
                int L1 = segments[i].get(j), L2 = segments[i].get(j+1);
                int k1 = Collections.binarySearch(segments[left], L1);
                if (k1 < 0)
                    k1 = Math.abs(k1)-1;
                int k2 = Collections.binarySearch(segments[left], L2);
                if (k2 < 0)
                    k2 = Math.abs(k2)-2;
                int k3 = Collections.binarySearch(segments[right], L1);
                if (k3 < 0)
                    k3 = Math.abs(k3)-1;
                int k4 = Collections.binarySearch(segments[right], L2);
                if (k4 < 0)
                    k4 = Math.abs(k4)-2;
                if (k2-k1 != k4-k3)
                    ans++;
            }
        }
        pw.print(ans);
        pw.close();
    }

    private static int nextInt() throws IOException{
        st.nextToken();
        return (int) st.nval;
    }

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Erik Odenman
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

    static final int max = 100005;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.getInt();
        int[] first = new int[max];
        int[][] attachments = new int[n][];
        for (int i = 0; i < n; i++) {
            int k = in.getInt();
            attachments[i] = new int[k];
            for (int j = 0; j < k; j++) {
                attachments[i][j] = in.getInt();
            }
            Arrays.sort(attachments[i]);
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            int[] prev = attachments[i == 0 ? n - 1 : i - 1];
            int[] next = attachments[i == n - 1 ? 0 : i + 1];
            for (int j = 0; j < attachments[i].length - 1; j++) {
                int l = attachments[i][j];
                int r = attachments[i][j + 1];
                int cnt1 = getInterval(l, r, prev);
                int cnt2 = getInterval(l, r, next);
                if (cnt1 != cnt2) {
                    //System.out.println("Found in: "+(i+1)+" cnt1="+cnt1+" cnt2="+cnt2);
                    res++;
                }
            }
        }
        out.println(res);
	}

    static int getInterval(int l, int r, int[] a) {
        if (a[0] > r || a[a.length - 1] < l) return 0;
        int li = binarySearch(l, a);
        if (a[li] > l) li--;
        int ri = binarySearch(r, a) + 1;
        return Math.max(0, ri - li - 1);
    }

    static int binarySearch(int val, int[] a) {
        int lo = 0; int hi = a.length - 1;
        while (lo < hi) {
            int mid = lo + (hi - lo) / 2 + 1;
            if (a[mid] <= val) {
                lo = mid;
            } else {
                hi = mid - 1;
            }
        }
        return lo;
    }

    }

class InputReader {
    private BufferedReader in;
    private StringTokenizer st;
    String token;

    public InputReader(InputStream inStream) {
        in = new BufferedReader(new InputStreamReader(inStream));
    }

    public int getInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        String res = peekToken();
        token = null;
        return res;
    }

    public String peekToken() {
        if (token != null) return token;
        while (st == null || !st.hasMoreTokens()) {
            String line = null;
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new RuntimeException("No more tokens was found");
            }
            if (line == null) return null;
            st = new StringTokenizer(line);
        }
        return token = st.nextToken();
    }

    }

class OutputWriter  {

    PrintWriter out;

    public OutputWriter(OutputStream outStream) {
        out = new PrintWriter(outStream);
    }

    public OutputWriter(Writer writer) {
        out = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) out.print(' ');
            out.print(objects[i]);
        }
    }

    public void println(Object... objects) {
        print(objects);
        out.println();
    }

    public void close() {
        out.close();
    }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Erik Odenman
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

    static final int max = 100005;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.getInt();
        int[] first = new int[max];
        int[][] attachments = new int[n][];
        for (int i = 0; i < n; i++) {
            int k = in.getInt();
            attachments[i] = new int[k];
            for (int j = 0; j < k; j++) {
                attachments[i][j] = in.getInt();
            }
            Arrays.sort(attachments[i]);
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            int[] prev = attachments[i == 0 ? n - 1 : i - 1];
            int[] next = attachments[i == n - 1 ? 0 : i + 1];
            for (int j = 0; j < attachments[i].length - 1; j++) {
                int l = attachments[i][j];
                int r = attachments[i][j + 1];
                int cnt1 = getInterval(l, r, prev);
                int cnt2 = getInterval(l, r, next);
                if (cnt1 != cnt2) {
                    res++;
                }
            }
        }
        out.println(res);
	}

    static int getInterval(int l, int r, int[] a) {
        int li = binarySearch(l, a);
        if (a[li] > l) li--;
        int ri = binarySearch(r, a) + 1;
        return Math.max(0, ri - li - 1);
    }

    static int binarySearch(int val, int[] a) {
        int lo = 0; int hi = a.length - 1;
        while (lo < hi) {
            int mid = lo + (hi - lo) / 2 + 1;
            if (a[mid] <= val) {
                lo = mid;
            } else {
                hi = mid - 1;
            }
        }
        return lo;
    }

    }

class InputReader {
    private BufferedReader in;
    private StringTokenizer st;
    String token;

    public InputReader(InputStream inStream) {
        in = new BufferedReader(new InputStreamReader(inStream));
    }

    public int getInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        String res = peekToken();
        token = null;
        return res;
    }

    public String peekToken() {
        if (token != null) return token;
        while (st == null || !st.hasMoreTokens()) {
            String line = null;
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new RuntimeException("No more tokens was found");
            }
            if (line == null) return null;
            st = new StringTokenizer(line);
        }
        return token = st.nextToken();
    }

    }

class OutputWriter  {

    PrintWriter out;

    public OutputWriter(OutputStream outStream) {
        out = new PrintWriter(outStream);
    }

    public OutputWriter(Writer writer) {
        out = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) out.print(' ');
            out.print(objects[i]);
        }
    }

    public void println(Object... objects) {
        print(objects);
        out.println();
    }

    public void close() {
        out.close();
    }
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class D extends D_Problem {

	void solve() {
		int n = nextInt();
		int[][] p = new int[n][];
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			p[i] = new int[k];
			for (int j = 0; j < k; j++)
				p[i][j] = nextInt();
			Arrays.sort(p[i]);
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			int a = i, b = (n + i - 1) % n, c = (i + 1) % n;
			int x = 0, y = 0, z = 0;
			while (x < p[a].length - 1) {
				int koly = 0, kolz = 0;
				while (p[b][y] <= p[a][x + 1] && y < p[b].length) {
					if (p[b][y] >= p[a][x] && p[b][y] <= p[a][x + 1])
						koly++;
					if (y < p[b].length - 1)
						y++; else break;
				}
				while (p[c][z] <= p[a][x + 1] && z < p[c].length) {
					if (p[c][z] >= p[a][x] && p[c][z] <= p[a][x + 1])
						kolz++;
					if (z < p[c].length - 1)
						z++; else break;
				}
				if (koly != kolz)
					ans++;
				x++;
			}
		}
		print(ans);
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
				new D_Solution().run();
			}
		}, "<3", 1 << 23).start();
	}
}

abstract class D_Problem {

	abstract void solve();

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tokenizer;

	void init(boolean oj) {
		Reader reader = null;
		Writer writer = null;
		if (oj) {
			reader = new InputStreamReader(System.in);
			writer = new OutputStreamWriter(System.out);
		} else
			try {
				reader = new FileReader("input.txt");
				writer = new FileWriter("output.txt");
			} catch (Exception e) {
				e.printStackTrace();
			}
		in = new BufferedReader(reader);
		out = new PrintWriter(writer);
	}

	void exit() {
		out.close();
		System.exit(0);
	}

	void print(Object... obj) {
		for (int i = 0; i < obj.length; i++) {
			if (i != 0)
				out.print(" ");
			out.print(obj[i]);
		}
	}

	void println(Object... obj) {
		print(obj);
		print("\n");
	}

	String nextLine() {
		try {
			return in.readLine();
		} catch (Exception e) {
			return "EOF";
		}
	}

	String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(nextLine());
		return tokenizer.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}
}

class D_Solution implements Runnable {
	private boolean oj;
	private long beginTime, beginMem, endTime, endMem;

	public void start() {
		oj = System.getProperty("ONLINE_JUDGE") != null;
		if (!oj) {
			beginTime = System.currentTimeMillis();
			beginMem = totalMemory() - freeMemory();
		}
	}

	public void finish() {
		if (!oj) {
			endMem = totalMemory() - freeMemory();
			endTime = System.currentTimeMillis();
			double mbUsed = 1d * (endMem - beginMem) / 8 / 1024 / 1024;
			double msPass = 1d * (endTime - beginTime) / 1000;
			System.out.println("Memory used = " + mbUsed + " mb");
			System.out.println("Running time = " + msPass + " s");
		}
	}

	public void run() {
		this.start();
		D_Problem problem = new D();
		problem.init(oj);
		problem.solve();
		problem.out.close();
		this.finish();
	}

	public long totalMemory() {
		return Runtime.getRuntime().totalMemory();
	}

	public long freeMemory() {
		return Runtime.getRuntime().freeMemory();
	}
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int count = in.readInt();
		int[][] positions = new int[count][];
		for (int i = 0; i < count; i++)
			positions[i] = IOUtils.readIntArray(in, in.readInt());
		for (int[] row : positions)
			ArrayUtils.sort(row, IntComparator.DEFAULT);
		int answer = 0;
		for (int i = 0; i < count; i++) {
			int last = (i + count - 1) % count;
			int next = (i + 1) % count;
			int lastIndex = 0;
			int nextIndex = 0;
			for (int j = 0; j < positions[i].length; j++) {
				int value = positions[i][j];
				int left = 0;
				int right = 0;
				while (lastIndex < positions[last].length && positions[last][lastIndex] < value) {
					lastIndex++;
					left++;
				}
				while (nextIndex < positions[next].length && positions[next][nextIndex] < value) {
					nextIndex++;
					right++;
				}
				if (j != 0 && left != right)
					answer++;
			}
		}
		out.printLine(answer);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	}

class ArrayUtils {
    private static int[] tempInt = new int[0];

	public static int[] sort(int[] array, IntComparator comparator) {
        return sort(array, 0, array.length, comparator);
    }

    public static int[] sort(int[] array, int from, int to, IntComparator comparator) {
        ensureCapacityInt(to - from);
        System.arraycopy(array, from, tempInt, 0, to - from);
        sortImpl(array, from, to, tempInt, 0, to - from, comparator);
        return array;
    }

    private static void ensureCapacityInt(int size) {
        if (tempInt.length >= size)
            return;
        size = Math.max(size, tempInt.length << 1);
        tempInt = new int[size];
    }

    private static void sortImpl(int[] array, int from, int to, int[] temp, int fromTemp, int toTemp, IntComparator comparator) {
        if (to - from <= 1)
            return;
        int middle = (to - from) >> 1;
        int tempMiddle = fromTemp + middle;
        sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle, comparator);
        sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);
        int index = from;
        int index1 = fromTemp;
        int index2 = tempMiddle;
        while (index1 < tempMiddle && index2 < toTemp) {
            if (comparator.compare(temp[index1], temp[index2]) <= 0)
                array[index++] = temp[index1++];
            else
                array[index++] = temp[index2++];
        }
        if (index1 != tempMiddle)
            System.arraycopy(temp, index1, array, index, tempMiddle - index1);
        if (index2 != toTemp)
            System.arraycopy(temp, index2, array, index, toTemp - index2);
    }

    }

interface IntComparator {
    public static final IntComparator DEFAULT = new IntComparator() {
        public int compare(int first, int second) {
            if (first < second)
                return -1;
            if (first > second)
                return 1;
            return 0;
        }
    };

    public int compare(int first, int second);
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt();

        ArrayList <ArrayList <Integer>> cobweb = new ArrayList <ArrayList <Integer>> ();

        for (int i = 0; i < n; ++i)
            cobweb.add(new ArrayList <Integer> ());

        for (int i = 0; i < n; ++i)
        {
            int k = sc.nextInt();
            for (int j = 0; j < k; ++j)
                cobweb.get(i).add(sc.nextInt());
        }

        for (int i = 0; i < n; ++i)
            Collections.sort(cobweb.get(i));

        int ans = 0;

        for (int i = 0; i < n; ++i)
        {
            int left = (i+n-1)%n;
            int right = (i+1)%n;

            int cur1 = 0;
            int cur2 = 0;

            for (int j = 0; j < cobweb.get(i).size()-1; ++j)
            {
                int balans = 0;

                while (cur1 < cobweb.get(left).size() && cobweb.get(left).get(cur1) < cobweb.get(i).get(j))
                    cur1++;

                while (cur1 < cobweb.get(left).size() && cobweb.get(left).get(cur1) <= cobweb.get(i).get(j+1))
                {
                    cur1++;
                    balans++;
                }

                while (cur2 < cobweb.get(right).size() && cobweb.get(right).get(cur2) < cobweb.get(i).get(j))
                    cur2++;

                while (cur2 < cobweb.get(right).size() && cobweb.get(right).get(cur2) <= cobweb.get(i).get(j+1))
                {
                    cur2++;
                    balans--;
                }

                ans += (balans == 0) ? 0 : 1;
            }
        }

        System.out.println(ans);
    }
}


import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class D {
	Scanner sc = new Scanner(System.in);
	void doIt()
	{
		int n = sc.nextInt();
		int[][] web = new int[n][];
		for(int i = 0; i < n; i++) {
			int k = sc.nextInt();
			web[i] = new int[k];
			for(int j = 0; j < k; j++) {
				web[i][j] = sc.nextInt();
			}
			sort(web[i]);
		}
		//debug(web);
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int dif = f(web[i], web[(i+1)%n], web[(i+n-1)%n]);
			ans += dif;
		}
		System.out.println(ans);
	}
	int f(final int[] target, final int[] left,  final int[] right) {
		int size = target.length;
		int [] pLeft = new int[size];
		int [] pRight = new int[size];
		for(int i = 0; i < size; i++) {
			pLeft[i] = Arrays.binarySearch(left, target[i]);
			pRight[i] = Arrays.binarySearch(right, target[i]);

		}
		//debug(pLeft);
		//debug(pRight);
		int res = 0;
		for(int i = 1; i < size; i++) {
			int l0 = pLeft[i-1] >= 0 ? pLeft[i-1] + 1 : - pLeft[i-1] + 1;
			int r0 = pRight[i-1] >= 0 ? pRight[i-1] : - pRight[i-1] + 1;
			int d0 = r0 - l0;
			int l1 = pLeft[i] >= 0 ? pLeft[i] + 1 : - pLeft[i] + 1;
			int r1 = pRight[i] >= 0 ? pRight[i] : - pRight[i] + 1;
			int d1 = r1 - l1;
			if(d0 != d1) {
				//System.err.print(i);
				res++;
			}
		}
		//debug(res);
		return res;
	}
	public static void main(String[] args) {
		new D().doIt();
	}
	void debug(Object...os) {
		System.err.println(deepToString(os));
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class D {

	static class Scanner
	{
		BufferedReader rd;
		StringTokenizer tk;
		public Scanner() throws IOException
		{
			rd=new BufferedReader(new InputStreamReader(System.in));
			tk=new StringTokenizer(rd.readLine());
		}
		public String next() throws IOException
		{
			while(!tk.hasMoreTokens())
				tk=new StringTokenizer(rd.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException
		{
			return Integer.valueOf(this.next());
		}
	}

	static int N;
	static int[][] sectors=new int[1010][];

	static int count(int[] array,int low,int sup){
		int first=Arrays.binarySearch(array, low);
		first++;first*=-1;//trick
		int second=Arrays.binarySearch(array, sup);
		second++;second*=-1;//trick
		return second-first;
	}

	public static void main(String args[]) throws IOException{
		//BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
		Scanner sc=new Scanner();
		N=sc.nextInt();
		for(int i=0;i<N;i++){
			int K=sc.nextInt();
			sectors[i]=new int[K];
			for(int j=0;j<K;j++)
				sectors[i][j]=sc.nextInt();
			Arrays.sort(sectors[i]);
		}

		int cells=0;
		for(int i=0;i<N;i++){
			int before=(i - 1 + N)%N;
			int after=(i + 1)%N;
			for(int j=0;j<sectors[i].length-1;j++){
				int first=sectors[i][j];
				int second=sectors[i][j+1];
				if (count(sectors[before],first,second)!=count(sectors[after],first,second))
					cells++;
			}
		}
		System.out.println(cells);

	}

}


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

public class D {
    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader buf = new BufferedReader(
                new InputStreamReader(System.in));
        int n = Integer.parseInt(buf.readLine());
        ArrayList<number>[] list = new ArrayList[n];
        for (int i = 0; i < list.length; i++) {
            list[i] = new ArrayList<number>();
        }
        for (int i = 0; i < n; i++) {
            String[] in = buf.readLine().split(" ");
            int k = Integer.parseInt(in[0]);
            int left = i - 1;
            int right = i + 1;
            if (left == -1)
                left = n - 1;
            if (right == n)
                right = 0;
            for (int j = 0; j < k; j++) {
                int x = Integer.parseInt(in[j + 1]);
                list[i].add(new number(0, x));
                list[left].add(new number(1, x));
                list[right].add(new number(2, x));
            }
        }
        for (int i = 0; i < n; i++)
            Collections.sort(list[i]);
        int count = 0;
        for (int i = 0; i < n; i++) {
            int m = list[i].size();
            int count1 = 0;
            int count2 = 0;
            int start = 0;
            while (start < m && list[i].get(start).color != 0)
                start++;
            for (int j = start + 1; j < m; j++) {
                if (list[i].get(j).color == 1)
                    count1++;
                else if (list[i].get(j).color == 2)
                    count2++;
                else {
                    if (count1 != count2)
                        count++;
                    count1 = 0;
                    count2 = 0;
                }
            }
        }
        System.out.println(count);

    }

    static class number implements Comparable<number> {

        int color;
        int value;

        public number(int col, int val) {
            color = col;
            value = val;
        }

        @Override
        public int compareTo(number arg0) {
            return value - arg0.value;
        }

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Prob216D {

	public static void main(String[] Args) {
		Scanner in = new Scanner(System.in);
		int threads = in.nextInt();

		int[] first = new int[in.nextInt()];
		for (int i = 0; i < first.length; i++)
			first[i] = in.nextInt();

		int[] second = new int[in.nextInt()];
		for (int i = 0; i < second.length; i++)
			second[i] = in.nextInt();

		int[] temp1 = Arrays.copyOf(first, first.length);
		int[] temp2 = Arrays.copyOf(second, second.length);
		int answer = 0;

		for (int i = 2; i < threads; i++) {
			int[] cur = new int[in.nextInt()];
			for (int j = 0; j < cur.length; j++)
				cur[j] = in.nextInt();

			answer += count(temp1, cur, temp2);
			temp1 = temp2;
			temp2 = cur;
		}

		answer += count(temp1, first, temp2);
		answer += count(temp2, second, first);

		System.out.println(answer);

	}

	public static int count(int[] ar1, int[] ar2, int[] current) {
		int answer = 0;
		int[] tempR = new int[current.length];
		int[] tempL = new int[current.length];

		int curIndex = 0;
		for (int j = 0; j < ar1.length; j++) {
			if (ar1[j] < current[curIndex])
				tempL[curIndex]++;
			else
				while (curIndex < current.length && ar1[j] > current[curIndex])
					curIndex++;

			if (curIndex == current.length)
				break;
		}

		curIndex = 0;
		for (int j = 0; j < ar2.length; j++) {
			if (ar2[j] < current[curIndex])
				tempR[curIndex]++;
			else
				while (curIndex < current.length && ar2[j] > current[curIndex])
					curIndex++;

			if (curIndex == current.length)
				break;
		}

		for (int j = 0; j < current.length; j++)
			if (tempL[j] != tempR[j])
				answer++;

		return answer;
	}
}