import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] p = new int[n]; for (int i = 0; i < n; i++) { p[i] = sc.nextInt() - 1; } sc.close(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[p[i]] = i; } int ans = 0; for (int i = 0; i < n; i++) { if (p[i] == i) { continue; } while (p[i] > i) { int x = a[p[i] - 1]; a[p[i] - 1] = i; a[p[i]] = x; p[i]--; p[x]++; ans++; } } System.out.println(ans); } }