import java.util.*;

public class Portal {

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

		int[] portals = new int[r];
		int[] rooms = new int[r];

		for (int i = 0; i < r; i++) {
			portals[i] = in.nextInt() - 1;
		}

		for (int i = 0; i < r; i++) {
			rooms[i] += 2;
			for (int j = portals[i]; j < i; j++) {
				rooms[i] += rooms[j];
				rooms[i] %= mod;
			}
		}

		int bob = 0;
		for (int i = 0; i < r; i++) {
			bob += rooms[i];
			bob %= bob;
		}
		System.out.println(bob);
	}
}


import java.util.*;

public class Portal {

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

		int[] portals = new int[r];
		int[] rooms = new int[r];

		for (int i = 0; i < r; i++) {
			portals[i] = in.nextInt() - 1;
		}

		for (int i = 0; i < r; i++) {
			rooms[i] += 2;
			for (int j = portals[i]; j < i; j++) {
				rooms[i] += rooms[j];
				rooms[i] %= mod;
			}
		}

		int bob = 0;
		for (int i = 0; i < r; i++) {
			bob += rooms[i];
			bob %= mod;
		}
		System.out.println(bob);
	}
}


import java.util.*;

public class Portal {

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

		int[] portals = new int[r];
		int[] rooms = new int[r];

		for (int i = 0; i < r; i++) {
			portals[i] = in.nextInt() - 1;
		}

		for (int i = 0; i < r; i++) {
			rooms[i] += 2;
			for (int j = portals[i]; j < i; j++) {
				rooms[i] += rooms[j];
			}
		}

		int bob = 0;
		for (int i = 0; i < r; i++) {
			bob += rooms[i];
		}
		System.out.println(bob);
	}
}


import java.util.Scanner;

public class LongPath {
	static int n;
	static int p[];

	static long dp[];

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

		n = sc.nextInt();
		p = new int[n + 1];

		for(int i = 1; i <= n; i++)
			p[i] = sc.nextInt();

		dp = new long[n + 1];

		dp[1] = 2;

		long res = 2;

		int mod = (int) 1e9 + 7;

		for(int i = 2; i <= n; i++) {
			dp[i] = 2;
			for(int j = p[i]; j < i; j++){
				dp[i] += dp[j];
				dp[i] %= mod;
			}

			res += dp[i];

			res %= mod;
		}

		System.out.println(res);

	}

}


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

public class CodeforceSol7a {
	static FastScanner in;
	static PrintWriter out;

	public static class FastScanner{
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in){
			br = new BufferedReader(new InputStreamReader(in));
		}

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

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

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

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		long numtests = in.nextLong();
		for(int notest = 0; notest < numtests; notest++){
			int n = in.nextInt();
			long[] jumps = new long[n+2];
			long[] to = new long[n+2];
			for(int idx = 0; idx < n; idx++){
				to[idx+1] = in.nextLong();
			}

			for(int vno = 2; vno <= n+1; vno++){
				jumps[vno] = ((2*jumps[vno-1]) + 2 - jumps[(int) to[vno-1]]) % 1000000007;
			}
			out.print(jumps[n+1]%1000000007);
		}

		out.close();
	}
}


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

public class CodeforceSol7a {
	static FastScanner in;
	static PrintWriter out;

	public static class FastScanner{
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in){
			br = new BufferedReader(new InputStreamReader(in));
		}

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

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

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

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		int n = in.nextInt();
		long[] jumps = new long[n+2];
		int[] to = new int[n+2];
		for(int idx = 0; idx < n; idx++){
			to[idx+1] = in.nextInt();
		}

		for(int vno = 2; vno <= n+1; vno++){
			jumps[vno] = (2*jumps[vno-1] + 2 - jumps[to[vno-1]]) % 1000000007;
		}
		long ans = jumps[n+1]%1000000007;
		if(ans < 0){
			ans += 1000000007;
		}
		out.print(ans);

		out.close();
	}
}


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

public class CodeforceSol7a {
	static FastScanner in;
	static PrintWriter out;

	public static class FastScanner{
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in){
			br = new BufferedReader(new InputStreamReader(in));
		}

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

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

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

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		int n = in.nextInt();
		long[] jumps = new long[n+2];
		long[] to = new long[n+2];
		for(int idx = 0; idx < n; idx++){
			to[idx+1] = in.nextLong();
		}

		for(int vno = 2; vno <= n+1; vno++){
			jumps[vno] = ((2*jumps[vno-1]) + 2 - jumps[(int) to[vno-1]]) % 1000000007;
		}
		out.print(jumps[n+1]%1000000007);

		out.close();
	}
}


import java.util.Scanner;

public class LongPath {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int goal = scan.nextInt();

		// mapportal holds where each room's second portal leads to
		int [] mapportal = new int[1000];

		for(int i = 0; i < goal; i++){
			mapportal[i] = scan.nextInt();
		}

		long [] prevAns = new long[1001];

		for(int i = 1; i <= goal; i++){
			prevAns[i] = (1000000007 + (prevAns[i - 1] + 1) * 2 - prevAns[mapportal[i - 1] - 1]) % 1000000007;
		}

		System.out.println(prevAns[goal]);

	}

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Map.Entry;

public class Main implements Runnable {
    static final int MOD = (int) 1e9 + 7;
    static final int MI = (int) 1e9;
    static final long ML = (long) 1e18;
    static final Reader in = new Reader();
    static final PrintWriter out = new PrintWriter(System.out);
    StringBuilder answer = new StringBuilder();

    public static void main(String[] args) {
        new Thread(null, new Main(), "persefone", 1 << 32).start();
    }

    @Override
    public void run() {
        solve();
        printf();
        flush();
    }

    void solve() {
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }
        /*
        dp[i] - ways to to reach i + 1 from i
        */
        int[] dp = new int[n + 1];
        int[] s = new int[n + 1];
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            dp[i] = i > a[i] ? (s[i - 1] - s[a[i] - 1] + 2 + MOD) % MOD : 2;
            s[i] = (s[i - 1] + dp[i]) % MOD;
            ans = (ans + dp[i]) % MOD;
        }
        printf(ans);
    }

    void printf() {
        out.print(answer);
    }

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

    void flush() {
        out.flush();
    }

    void printf(Stream<?> str) {
        str.forEach(o -> add(o, " "));
        add("\n");
    }

    void printf(Object... obj) {
        printf(false, obj);
    }

    void printfWithDescription(Object... obj) {
        printf(true, obj);
    }

    private void printf(boolean b, Object... obj) {

        if (obj.length > 1) {
            for (int i = 0; i < obj.length; i++) {
                if (b) add(obj[i].getClass().getSimpleName(), " - ");
                if (obj[i] instanceof Collection<?>) {
                    printf((Collection<?>) obj[i]);
                } else if (obj[i] instanceof int[][]) {
                    printf((int[][]) obj[i]);
                } else if (obj[i] instanceof long[][]) {
                    printf((long[][]) obj[i]);
                } else if (obj[i] instanceof double[][]) {
                    printf((double[][]) obj[i]);
                } else printf(obj[i]);
            }
            return;
        }

        if (b) add(obj[0].getClass().getSimpleName(), " - ");
        printf(obj[0]);
    }

    void printf(Object o) {
        if (o instanceof int[])
            printf(Arrays.stream((int[]) o).boxed());
        else if (o instanceof char[])
            printf(new String((char[]) o));
        else if (o instanceof long[])
            printf(Arrays.stream((long[]) o).boxed());
        else if (o instanceof double[])
            printf(Arrays.stream((double[]) o).boxed());
        else if (o instanceof boolean[]) {
            for (boolean b : (boolean[]) o) add(b, " ");
            add("\n");
        } else
            add(o, "\n");
    }

    void printf(int[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(long[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(double[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(boolean[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(Collection<?> col) {
        printf(col.stream());
    }

    <T, K> void add(T t, K k) {
        if (t instanceof Collection<?>) {
            ((Collection<?>) t).forEach(i -> add(i, " "));
        } else if (t instanceof Object[]) {
            Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
        } else
            add(t);
        add(k);
    }

    <T> void add(T t) {
        answer.append(t);
    }

    static class Reader {
        private BufferedReader br;
        private StringTokenizer st;

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

        Reader(String fileName) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(fileName));
        }

        boolean isReady() throws IOException {
            return br.ready();
        }

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

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

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }

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

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Map.Entry;

public class Main implements Runnable {
    static final int MOD = (int) 1e9 + 7;
    static final int MI = (int) 1e9;
    static final long ML = (long) 1e18;
    static final Reader in = new Reader();
    static final PrintWriter out = new PrintWriter(System.out);
    StringBuilder answer = new StringBuilder();

    public static void main(String[] args) {
        new Thread(null, new Main(), "persefone", 1 << 32).start();
    }

    @Override
    public void run() {
        solve();
        printf();
        flush();
    }

    void solve() {
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }
        /*
        dp[i] - ways to to reach i + 1 from i
        */
        int[] dp = new int[n + 1];
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i > a[i]) {
                for (int j = a[i]; j < i; j++) {
                    dp[i] = (dp[i] + dp[j]) % MOD;
                }
            }
            dp[i] = (dp[i] + 2) % MOD;
            ans = (ans + dp[i]) % MOD;
        }
        printf(ans);
    }

    void printf() {
        out.print(answer);
    }

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

    void flush() {
        out.flush();
    }

    void printf(Stream<?> str) {
        str.forEach(o -> add(o, " "));
        add("\n");
    }

    void printf(Object... obj) {
        printf(false, obj);
    }

    void printfWithDescription(Object... obj) {
        printf(true, obj);
    }

    private void printf(boolean b, Object... obj) {

        if (obj.length > 1) {
            for (int i = 0; i < obj.length; i++) {
                if (b) add(obj[i].getClass().getSimpleName(), " - ");
                if (obj[i] instanceof Collection<?>) {
                    printf((Collection<?>) obj[i]);
                } else if (obj[i] instanceof int[][]) {
                    printf((int[][]) obj[i]);
                } else if (obj[i] instanceof long[][]) {
                    printf((long[][]) obj[i]);
                } else if (obj[i] instanceof double[][]) {
                    printf((double[][]) obj[i]);
                } else printf(obj[i]);
            }
            return;
        }

        if (b) add(obj[0].getClass().getSimpleName(), " - ");
        printf(obj[0]);
    }

    void printf(Object o) {
        if (o instanceof int[])
            printf(Arrays.stream((int[]) o).boxed());
        else if (o instanceof char[])
            printf(new String((char[]) o));
        else if (o instanceof long[])
            printf(Arrays.stream((long[]) o).boxed());
        else if (o instanceof double[])
            printf(Arrays.stream((double[]) o).boxed());
        else if (o instanceof boolean[]) {
            for (boolean b : (boolean[]) o) add(b, " ");
            add("\n");
        } else
            add(o, "\n");
    }

    void printf(int[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(long[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(double[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(boolean[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(Collection<?> col) {
        printf(col.stream());
    }

    <T, K> void add(T t, K k) {
        if (t instanceof Collection<?>) {
            ((Collection<?>) t).forEach(i -> add(i, " "));
        } else if (t instanceof Object[]) {
            Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
        } else
            add(t);
        add(k);
    }

    <T> void add(T t) {
        answer.append(t);
    }

    static class Reader {
        private BufferedReader br;
        private StringTokenizer st;

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

        Reader(String fileName) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(fileName));
        }

        boolean isReady() throws IOException {
            return br.ready();
        }

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

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

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }

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

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}


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

public class Portals
{
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int rooms = in.nextInt();
		int[] portals = new int[rooms];
		for(int i = 0; i < rooms; i++) {
			portals[i] = in.nextInt() - 1;
		}

		int[] numPaths = new int[rooms];
		int totalPaths = 0;
		for(int i = 0; i < rooms; i++) {
			numPaths[i] += 2;
			for(int j = portals[i]; j < i; j++) {
				numPaths[i] += numPaths[j];
				numPaths[i] %= 1000000007;
			}
			totalPaths += numPaths[i];
			totalPaths %= 1000000007;
		}

		System.out.println(totalPaths);
	}
}


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

public class Portals
{
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int rooms = in.nextInt();
		int[] portals = new int[rooms];
		for(int i = 0; i < rooms; i++) {
			portals[i] = in.nextInt() - 1;
		}

		int[] numPaths = new int[rooms];
		int totalPaths = 0;
		for(int i = 0; i < rooms; i++) {
			numPaths[i] += 2;
			for(int j = portals[i]; j < i; j++) {
				numPaths[i] += numPaths[j];
			}
			totalPaths += numPaths[i];
		}

		System.out.println(totalPaths);
	}
}


package com.himanshu.practice.july9;

import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Created by himanshubhardwaj on 09/07/18.
 * CodeForces: https://codeforces.com/problemset/problem/407/B
 */
public class LongPath {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int arr[] = new int[n + 2];
        StringTokenizer st = new StringTokenizer(sc.nextLine(), " ");

        for (int i = 1; i <= n; i++) {
            String str = st.nextToken();
            //System.out.println(str);
            arr[i] = Integer.parseInt(str);
        }

        long DP[][] = new long[n + 2][2];

        for (int i = 0; i < DP.length; i++) {
            for (int j = 0; j < DP[0].length; j++) {
                DP[i][j] = Long.MIN_VALUE;
            }
        }

        DP[n][0] = 1;
        DP[n + 1][0] = 0;
        DP[n + 1][1] = 0;

        int[] numCross = new int[n + 2];

        //getMin(DP,1);
        System.out.print(getMin(DP, 1, 1, numCross, arr, n));

    }

    //forget DP for a second
    private static long getMin(long[][] dp, int pos, int numCrossModulo, int[] numCross, int[] direction, int n) {
        if (pos == (n + 1)) {
            return 0;
        }
        numCross[pos]++;

        if ((numCross[pos] % 2) == 0) {
            return (1 + getMin(dp, pos + 1, 0, numCross, direction, n)) % 1000000007;
        } else {
            return (1 + getMin(dp, direction[pos], 0, numCross, direction, n)) % 1000000007;
        }
    }
}


//package com.himanshu.practice.july9;

import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Created by himanshubhardwaj on 09/07/18.
 * CodeForces: https://codeforces.com/problemset/problem/407/B
 */
public class LongPath {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int arr[] = new int[n + 2];
        StringTokenizer st = new StringTokenizer(sc.nextLine(), " ");

        for (int i = 1; i <= n; i++) {
            String str = st.nextToken();
            //System.out.println(str);
            arr[i] = Integer.parseInt(str);
        }

        long DP[][] = new long[n + 2][2];

        for (int i = 0; i < DP.length; i++) {
            for (int j = 0; j < DP[0].length; j++) {
                DP[i][j] = Long.MIN_VALUE;
            }
        }

        DP[n][0] = 1;
        DP[n + 1][0] = 0;
        DP[n + 1][1] = 0;

        int[] numCross = new int[n + 2];

        //getMin(DP,1);
        System.out.print(getMin(DP, 1, 1, numCross, arr, n));

    }

    //forget DP for a second
    private static long getMin(long[][] dp, int pos, int numCrossModulo, int[] numCross, int[] direction, int n) {
        if (pos == (n + 1)) {
            return 0;
        }
        numCross[pos]++;

        if ((numCross[pos] % 2) == 0) {
            return (1 + getMin(dp, pos + 1, 0, numCross, direction, n)) % 1000000007;
        } else {
            return (1 + getMin(dp, direction[pos], 0, numCross, direction, n)) % 1000000007;
        }
    }
}


//package com.himanshu.practice.july9;

import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Created by himanshubhardwaj on 09/07/18.
 * CodeForces: https://codeforces.com/problemset/problem/407/B
 * Algo: DP
 */
public class LongPath {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int arr[] = new int[n + 1];//1...n
        StringTokenizer st = new StringTokenizer(sc.nextLine(), " ");

        for (int i = 1; i <= n; i++) {
            String str = st.nextToken();
            arr[i] = Integer.parseInt(str);
        }

//        System.out.print(getMinBruteforce(1, arr));
//        System.out.println();
        System.out.print(getMinDP(arr));
    }

    //forget DP for a second
    //and this is our bruteforce
    private static long getMinBruteforce(int pos, int[] direction) {
        int n = direction.length - 1;
        long sum = 0;
        int[] numCross = new int[n + 1];

        int sumA[][] = new int[n + 2][2];
        boolean isSetSumA[][] = new boolean[n + 2][2];
        sumA[n][0] = 1;

        while (pos != (n + 1)) {
            if (isSetSumA[pos][numCross[pos] % 2]) {
                sum = (sum + sumA[pos][numCross[pos] % 2]) % 1000000007;
                break;
            } else {

            }
            numCross[pos] = (numCross[pos] + 1) % 1000000007;
            sum = (sum + 1) % 1000000007;

            System.out.println(sum);

            if ((numCross[pos] % 2) == 0) {
                pos++;
            } else {
                pos = direction[pos];
            }
        }
        return sum;
    }

    //DP
    private static long getMinDP(int[] direction) {
        int n = direction.length - 1;

        int dp[] = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            dp[i] = 1;
            for (int j = direction[i]; j < i; j++) {
                dp[i] = (dp[i] + (1 + dp[j])) % 1000000007;
            }
        }

        long sum = 0;
        for (int i = 1; i <= n; i++) {
            sum = (sum + dp[i] + 1) % 1000000007;
        }
        return sum;
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(new BufferedInputStream(System.in));

		int n = cin.nextInt();
		long MOD = 1000000007L;
		int[] p = new int[n + 1];
		long[] dp = new long[n + 1];

		for (int i = 1; i <= n; i++)
			p[i] = cin.nextInt();

		dp[1] = 2L;
		for (int i = 2; i <= n; i++)
			dp[i] = (2L * dp[i - 1] - dp[p[i] - 1] + 2L) % MOD;

		System.out.println(dp[n] < 0 ? dp[n] + MOD : dp[n]);
		cin.close();
	}

}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(new BufferedInputStream(System.in));

		int n = cin.nextInt();
		long MOD = 1000000007L;
		int[] p = new int[n + 1];
		long[] dp = new long[n + 1];

		for (int i = 1; i <= n; i++)
			p[i] = cin.nextInt();

		dp[1] = 2L;
		for (int i = 2; i <= n; i++)
			dp[i] = (2L * dp[i - 1] - dp[p[i] - 1] + 2L) % MOD;

		System.out.println(dp[n]);
		cin.close();
	}

}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(new BufferedInputStream(System.in));

		int n = cin.nextInt();
		long MOD = 1000000007L;
		int[] p = new int[n + 1];
		long[] dp = new long[n + 1];

		for (int i = 1; i <= n; i++)
			p[i] = cin.nextInt();

		dp[1] = 2L;
		for (int i = 2; i <= n; i++)
			dp[i] = (2 * dp[i - 1] - dp[p[i] - 1] + 2L) % MOD;

		System.out.println(dp[n]);
		cin.close();
	}

}


import java.util.*;

public class Main {

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

		int n = sc.nextInt();
		long[][] meta = new long[2][2]; //arrival portal, portals to loops through
		int[] maze = new int[n+1];
		//If you ever land on an old block, you're going to repeat the same pattern to get out
		//hence you will have to run through the same loop so just cache the number of portals already computed

		for(int i = 1; i < maze.length; i++){
			maze[i] = sc.nextInt();
		}
		sc.close();

		long portals =0, temp =0;
		int pos = 1, old_pos;
		while(pos < n+1){
			if(maze[pos] == -2){ //if visited twice before and recorded the # of portals
				portals += meta[1][pos%2];
				pos++;
			}
			else if(maze[pos] == -1){ //if visiting for the second time
				temp = portals - meta[0][pos%2]; //number of portals it takes to visit again
				meta[1][pos%2] = temp % mod;
				maze[pos++] = -2;
				portals = (portals + temp) % mod;
			}
			else{ //visiting for the first time
				meta[0][pos%2] = portals % mod;
				old_pos = pos;
				pos = maze[pos];
				maze[old_pos] = -1; //mark as visited
				portals = (portals + 1) % mod; //so much mod. so much.
			}

		}

		System.out.println(portals);
	}
}


import java.util.*;

public class Main {

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

		int n = sc.nextInt();
		long[][] meta = new long[2][n+1]; //arrival portal, portals to loops through
		int[] maze = new int[n+1];
		//If you ever land on an old block, you're going to repeat the same pattern to get out
		//hence you will have to run through the same loop.

		for(int i = 1; i < maze.length; i++){
			maze[i] = sc.nextInt();
		}
		sc.close();

		long portals =0, temp =0;
		int pos = 1, old_pos;
		while(pos < n+1){
			if(meta[1][pos] != 0){ //if visited twice before and recorded the # of portals
				portals += meta[1][pos++];
			}
			else if(maze[pos] == -1){ //if visiting for the second time
				temp = portals - meta[0][pos]; //number of portals it takes to visit again
				meta[1][pos++] = temp % mod;
				portals = (portals + temp) % mod;
			}
			else{ //visiting for the first time
				meta[0][pos] = portals % mod;
				old_pos = pos;
				pos = maze[pos];
				maze[old_pos] = -1; //mark as visited
				portals = (portals + 1) % mod; //so much mod. so much.
			}

		}

		System.out.println(portals);
	}
}


import java.util.*;

public class Main{

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

		int n = sc.nextInt();
		long[][] meta = new long[3][n+1]; //maze, cross, arrival portal, portals to loops through
		int[] maze = new int[n+1];
		//If you ever land on an old block, you're going to repeat the same pattern to get out
		//hence you will have to run through the same loop.

		for(int i = 1; i < maze.length; i++){
			maze[i] = sc.nextInt();
		}
		sc.close();

		long portals =0, temp =0;
		int pos = 1, old_pos;
		while(pos < n+1){
			if(meta[2][pos] != 0){ //if visited twice before and recorded the # of portals
				portals += meta[2][pos++];
			}
			else if(maze[pos] == -1){ //if visiting for the second time
				temp = portals - meta[1][pos]; //number of portals it takes to visit again
				meta[2][pos++] = temp % mod;
				portals = (portals + temp) % mod;
			}
			else{ //visiting for the first time
				meta[0][pos]++;
				meta[1][pos] = portals % mod;
				old_pos = pos;
				pos = maze[pos];
				maze[old_pos] = -1; //mark as visited
				portals = (portals + 1) % mod; //so much mod. so much.
			}

		}

		System.out.println(portals);
	}
}


import java.io.File;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class p020 {
	public static void main(String args[]) throws Exception {
		StringTokenizer stok = new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next());
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(stok.nextToken());
		int[] a = new int[n+1];
		for (int i = 1; i < n+1; i++) {
			a[i] = Integer.parseInt(stok.nextToken());
		}
		int[] dp = new int[n+1];
		dp[1]=2;
		for(int i=2;i<=n;i++) {
			dp[i]=2;
			for(int j=a[i];j<i;j++) dp[i]+=dp[j];
		}
		System.out.println(Arrays.stream(dp).sum());
	}
}


import java.io.File;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class p020 {
	public static void main(String args[]) throws Exception {
		StringTokenizer stok = new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next());
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(stok.nextToken());
		int[] a = new int[n+1];
		for (int i = 1; i < n+1; i++) {
			a[i] = Integer.parseInt(stok.nextToken());
		}
		long[] dp = new long[n+1];
		long mod = (long)1e9+7;
		dp[1]=2;
		for(int i=2;i<=n;i++) {
			dp[i]=2;
			for(int j=a[i];j<i;j++) dp[i]=(dp[i]+dp[j])%mod;
		}
		System.out.println((Arrays.stream(dp).sum())%mod);
	}
}


import java.util.Scanner;

/**
 * Created by Rohit on 10/21/15.
 */
public class LongPath {

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

        int[] dp = new int[n + 1];
        for(int i = 1; i <= n; i++){
            dp[i] = ((((2*dp[i-1] - dp[sc.nextInt() -1]) + 2) % bound + bound) % bound);
        }
        System.out.println(dp[n]);
    }
}


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

public class A {

	static final int mod = (int)1e9 + 7;
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt(), p[] = new int[n];
		for(int i = 0; i < n; ++i)
			p[i] = sc.nextInt() - 1;
		int[] prefix = new int[n];
		prefix[0] = 2;
		for(int i = 1; i < n; ++i)
		{
			prefix[i] = (1+prefix[i-1]<<1)%mod;
			if(p[i] > 0)
				prefix[i] = (prefix[i] - prefix[p[i]-1] + mod)%mod;
		}
		out.println(prefix[n-1]);
		out.flush();
		out.close();

	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		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 boolean ready() throws IOException {return br.ready();}

	}
}


import java.util.*;
public class LongPath {

    static int mod = 1000000007;

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] p = new int[n];
        for(int i = 0; i<n; i++)
            [i] = input.nextInt()-1;
        int[] dp = new int[n];
        for(int i = 0; i<n; i++)
        {
            if(p[i] == i) dp[i] = 2;
            else
            {
                int tot = 1, at = p[i];
                while(at < i)
                {
                    tot = (tot+dp[at])%mod;
                    at++;
                }
                dp[at] = (tot+1)%mod;
            }
        }
        int res = 0;
        for(int i = 0; i<n; i++)
            res = (res +dp[i])%mod;
        System.out.println(res);

    }
}


import java.util.*;
public class LongPath {

    static int mod = 1000000007;

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] p = new int[n];
        for(int i = 0; i<n; i++)
            p[i] = input.nextInt()-1;
        int[] dp = new int[n];
        for(int i = 0; i<n; i++)
        {
            if(p[i] == i) dp[i] = 2;
            else
            {
                int tot = 1, at = p[i];
                while(at < i)
                {
                    tot = (tot+dp[at])%mod;
                    at++;
                }
                dp[at] = (tot+1)%mod;
            }
        }
        int res = 0;
        for(int i = 0; i<n; i++)
            res = (res +dp[i])%mod;
        System.out.println(res);

    }
}


import java.util.*;
public class LongPath {

    static int mod = 1000000007;

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] p = new int[n];
        for(int i = 0; i<n; i++) {
            [i] = input.nextInt()-1;
        }
        int[] dp = new int[n];
        for(int i = 0; i<n; i++)
        {
            if(p[i] == i) dp[i] = 2;
            else
            {
                int tot = 1, at = p[i];
                while(at < i)
                {
                    tot = (tot+dp[at])%mod;
                    at++;
                }
                dp[at] = (tot+1)%mod;
            }
        }
        int res = 0;
        for(int i = 0; i<n; i++)
            res = (res +dp[i])%mod;
        System.out.println(res);

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class B407
{
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is)
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }

    }

    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        int p[]=in.nextIntArrayOneBased(n);
        long dp[]=new long[n+2];
        long mod=1000000007;
        for(int i=1;i<=n;i++)
            dp[i+1]=(2*dp[i]+2-dp[p[i]])%mod;
        if(dp[n+1]<0)
            dp[n+1]+=mod;
        out.println(dp[n+1]);
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class B407
{
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is)
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }

    }

    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        int p[]=in.nextIntArrayOneBased(n);
        long dp[]=new long[n+2];
        long mod=1000000007;
        for(int i=1;i<=n;i++)
            dp[i+1]=(2*dp[i]+2-dp[p[i]])%mod;
        if(dp[n+1]<0)
            dp[n+1]%=mod;
        out.println(dp[n+1]);
        out.close();
    }

}


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

public class temp4 {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	static class Print
	{
	    private final BufferedWriter bw;
	    public Print()
	    {
	        bw=new BufferedWriter(new OutputStreamWriter(System.out));
	    }
	    public void print(String str)throws IOException
	    {
	        bw.append(str);
	    }
	    public void println(String str)throws IOException
	    {
	        print(str);
	        bw.append("\n");
	    }
	    public void close()throws IOException
	    {
	        bw.close();
	    }}

		public static void main(String[] args) throws IOException {
			FastReader scn=new FastReader();
			int n=scn.nextInt(),m=1000000007;
			long[] inf=new long[n+1];
			int[] p=new int[n];
			for(int i=0;i<n;i++){
				p[i]=scn.nextInt();
			}
			inf[0]=0;
			for(int i=0;i<n;i++){
				inf[i+1]=(inf[i]+1+inf[i]-inf[p[i]-1]+1+m)%m;
			}
			System.out.println(inf[n]);
		}
}


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...
 */
public class Main
{
	public static void main(String[] args)
	{
		int n=ni();
		int p[]=nia(n);
		long[] dp=new long[n+1];
		for(int i=0; i<n; i++)
			dp[i+1]=(2*dp[i]-dp[p[i]]+2)%mod;
		sop(dp[n]);
		System.out.println(output);
	}

	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static final long 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 psort(Integer[][] a)
	{
		Arrays.sort(a, new Comparator<Integer[]>()
		{
			@Override
			public int compare(Integer[]a,Integer[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(b[0]>a[1])
					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.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	public static void main(String[] args)
	{
		int n=ni();
		int p[]=nia(n);
		long[] dp=new long[n+1];
		for(int i=0; i<n; i++)
			dp[i+1]=(2*dp[i]-dp[p[i]-1]+2)%mod;
		sop(dp[n]);
		System.out.println(output);
	}

	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static final long 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 psort(Integer[][] a)
	{
		Arrays.sort(a, new Comparator<Integer[]>()
		{
			@Override
			public int compare(Integer[]a,Integer[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(b[0]>a[1])
					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.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	public static void main(String[] args)
	{
		int n=ni();
		int p[]=nia(n);
		long[] dp=new long[n+1];
		for(int i=0; i<n; i++)
			dp[i+1]=(2*dp[i]-dp[p[i]-1]+2)%mod;
		sop((dp[n]+mod)%mod);
		System.out.println(output);
	}

	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static final long 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 psort(Integer[][] a)
	{
		Arrays.sort(a, new Comparator<Integer[]>()
		{
			@Override
			public int compare(Integer[]a,Integer[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(b[0]>a[1])
					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.util.Scanner;

public class LongPath{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] dp = new long[n + 1];
		int[] arr = new int[n + 1];
		long m = 1000000007L;
		for (int i = 1; i <= n; i++)
			arr[i] = scan.nextInt();
		for (int i = 1; i <= n; i++) {
			dp[i] = (2 * dp[i - 1] - dp[arr[i] - 1] + 2 + m) % m;
		}
		System.out.println(dp[n]);
	}
}


import java.util.Stack;
import java.io.DataInputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.IOException;

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

		public Reader()
		{
			din = new DataInputStream(System.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[201]; // 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();
		}
	}

        public static void main(String[] args) throws IOException
	{
		Reader s=new Reader();PrintWriter pw=new PrintWriter(System.out);
                int n=s.nextInt();
                int a[]=new int[n+1];
                for(int i=1;i<=n;i++)a[i]=s.nextInt();
                long mod=(long)(1E+9)+7;
                Stack<Integer> st=new Stack<>();
                long tm[]=new long[n+1];
                for(int i=1;i<=n;i++){
                 int j=i;
                 while(true){
                  st.add(j);tm[i]++;
                  if(j==a[j])break;
                  j=a[j];
                 }
                 int id=-1;
                 while(!st.isEmpty()){
                  int pid=st.peek();
                  if(id!=-1)tm[i]=(tm[i]+tm[pid-1]-tm[id])%mod;
                  tm[i]++;id=pid;st.pop();
                 }
                 tm[i]=(tm[i-1]+tm[i])%mod;
                }//for(int i=1;i<=n;i++)System.out.print(tm[i]+" ");
                pw.write(tm[n]+"");
		pw.flush();pw.close();
	}
}


import java.io.DataInputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.IOException;

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

		public Reader()
		{
			din = new DataInputStream(System.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[201]; // 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();
		}
	}

        public static void main(String[] args) throws IOException
	{
		Reader s=new Reader();PrintWriter pw=new PrintWriter(System.out);
                int n=s.nextInt();
                int a[]=new int[n+1];
                for(int i=1;i<=n;i++)a[i]=s.nextInt();
                long mod=(long)(1E+9)+7;
                long tm[]=new long[n+1];
                for(int i=1;i<=n;i++){
                 tm[i]=(2+tm[i-1]+tm[i-1]-tm[a[i]-1]+mod)%mod;
                }
                pw.write(tm[n]+"");
		pw.flush();pw.close();
	}
}


import java.util.Stack;
import java.io.DataInputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.IOException;

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

		public Reader()
		{
			din = new DataInputStream(System.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[201]; // 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();
		}
	}

        public static void main(String[] args) throws IOException
	{
		Reader s=new Reader();PrintWriter pw=new PrintWriter(System.out);
                int n=s.nextInt();
                int a[]=new int[n+1];
                for(int i=1;i<=n;i++)a[i]=s.nextInt();
                long mod=(long)(1E+9)+7;
                Stack<Integer> st=new Stack<>();
                long tm[]=new long[n+1];
                for(int i=1;i<=n;i++){
                 int j=i;
                 while(true){
                  st.add(j);tm[i]++;
                  if(j==a[j])break;
                  j=a[j];
                 }
                 int id=-1;
                 while(!st.isEmpty()){
                  int pid=st.peek();
                  if(id!=-1)tm[i]=(tm[i]+tm[pid-1]-tm[id]+mod)%mod;
                  tm[i]++;id=pid;st.pop();
                 }
                 tm[i]=(tm[i-1]+tm[i])%mod;
                }
                pw.write(tm[n]+"");
		pw.flush();pw.close();
	}
}


import java.util.*;

public class Mazies
{
	public static void main(String[] args)
	{
		Scanner reader = new Scanner(System.in);
		int m = 1000000007;
		int n = reader.nextInt();
		int[] portals = new int[n+1];
		for(int i = 1; i <= n; i++)
		{
			portals[i] = reader.nextInt();
		}

		int[] stepsToPass = new int[n + 1];
		stepsToPass[1] = 2;
		for(int i = 1; i <= n; i++)
		{
			int goBackTo = portals[i];
			stepsToPass[i] = 2;
			for(int j = goBackTo; j < i; j++)
			{
				// (a + b) % m = ((a % m) + (b % m)) % m
				int a = stepsToPass[i];
				int b = stepsToPass[j];
				stepsToPass[i] = ((a % m) + (b % m)) % m;
			}
		}

		int sum = 0;
		for(int i = 0; i <= n; i++)
		{
			int a = sum;
			int b = stepsToPass[i];
			sum = ((a % m) + (b % m)) % m;
		}

		System.out.println(sum);
	}
}


import java.util.*;

public class Mazies
{
	public static void main(String[] args)
	{
		Scanner reader = new Scanner(System.in);
		int m = 1000000007;
		int n = reader.nextInt();
		int[] portals = new int[n+1];
		for(int i = 1; i <= n; i++)
		{
			portals[i] = reader.nextInt();
		}

		int[] stepsToPass = new int[n + 1];
		stepsToPass[1] = 2;
		for(int i = 1; i <= n; i++)
		{
			int goBackTo = portals[i];
			stepsToPass[i] = 2;
			for(int j = goBackTo; j < i; j++)
			{
				// (a + b) % m = ((a % m) + (b % m)) % m
				int a = stepsToPass[i];
				int b = stepsToPass[j];
				stepsToPass[i] = ((a % m) + (b % m)) % m;
			}
		}

		int sum = 0;
		for(int i = 0; i <= n; i++)
		{
			sum += stepsToPass[i];
		}

		System.out.println(sum);
	}
}


import java.util.*;

public class Mazies
{
	public static void main(String[] args)
	{
		Scanner reader = new Scanner(System.in);
		int n = reader.nextInt();
		int[] portals = new int[n+1];
		for(int i = 1; i <= n; i++)
		{
			portals[i] = reader.nextInt();
		}

		int[] stepsToPass = new int[n + 1];
		stepsToPass[1] = 2;
		for(int i = 1; i <= n; i++)
		{
			int goBackTo = portals[i];
			stepsToPass[i] = 2;
			for(int j = goBackTo; j < i; j++)
			{
				stepsToPass[i] = stepsToPass[i] + stepsToPass[j];
			}
		}

		int sum = 0;
		for(int i = 0; i <= n; i++)
		{
			sum += stepsToPass[i];
		}

		System.out.println(sum);
	}
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.InputMismatchException;

public class LongPath {
	static class Solver {

		int N, p[], exit[];
		int add(int a, int b) { return (a + b) % 1_000_000_007; }

		void solve(int testNumber, FastScanner s, PrintWriter out) {
			N = s.nextInt(); p = new int[N]; exit = new int[N];
			for(int i = 0; i < N; i++) p[i] = s.nextInt() - 1;

			Arrays.fill(exit, 2);
			int res = 2;
			for(int i = 1; i < N; i++) {
				int j = p[i];
				while(j < i) exit[i] = add(exit[i], exit[j++]);
				res = add(res, exit[i]);
			}
			out.println(res);
		}

	}

	final static boolean cases = false;

	public static void main(String[] args) {

		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		Solver solver = new Solver();
		for (int t = 1, T = cases ? s.nextInt() : 1; t <= T; t++)
			solver.solve(t, s, out);

		out.close();

	}

	static int min(int a, int b) {
		return a < b ? a : b;
	}

	static int max(int a, int b) {
		return a > b ? a : b;
	}

	static long min(long a, long b) {
		return a < b ? a : b;
	}

	static long max(long a, long b) {
		return a > b ? a : b;
	}

	static int swap(int a, int b) {
		return a;
	}

	static Object swap(Object a, Object b) {
		return a;
	}

	static String ts(Object... o) {
		return Arrays.deepToString(o);
	}

	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

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

		public FastScanner(File f) throws FileNotFoundException {
			this(new FileInputStream(f));
		}

		public FastScanner(String s) {
			this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
		}

		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++];
		}

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

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

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

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

		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		// Jacob Garbage

		public int[] nextIntArray(int N) {
			int[] ret = new int[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextInt();
			return ret;
		}

		public int[][] next2DIntArray(int N, int M) {
			int[][] ret = new int[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextIntArray(M);
			return ret;
		}

		public long[] nextLongArray(int N) {
			long[] ret = new long[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextLong();
			return ret;
		}

		public long[][] next2DLongArray(int N, int M) {
			long[][] ret = new long[N][];
			for (int i = 0; i < N; i++)
				ret[i] = nextLongArray(M);
			return ret;
		}

		public double[] nextDoubleArray(int N) {
			double[] ret = new double[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDouble();
			return ret;
		}

		public double[][] next2DDoubleArray(int N, int M) {
			double[][] ret = new double[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDoubleArray(M);
			return ret;
		}

	}
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

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

		public Reader() {
			din = new DataInputStream(System.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();
		}
	}

	public static void main(String ar[]) throws IOException {
		Reader reader = new Reader();
		int n = reader.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; i += 1) {
			p[i] = reader.nextInt() - 1;
		}

		int dp[] = new int[n];
		int MOD = 1000000007;
		for (int i = 0; i < n; i += 1) {
			dp[i] = 2;
			for (int ptr = p[i]; ptr < i; ptr += 1) {
				dp[i] = (dp[i] + dp[ptr]) % MOD;
			}
		}

		long ans = 0;
		for (int i = 0; i < n; i += 1) {
			ans = (ans + dp[i]) % MOD;
		}
		System.out.println(ans);
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                            //(new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        int MOD = (int)1e9+7;
        int n = parseInt(in.readLine());
        int [] p = new int[n+2];

        tk = new StringTokenizer(in.readLine());
        for(int i=1; i<=n; i++)
            p[i] = parseInt(tk.nextToken());

        int [] dp = new int[n+2];
        dp[1] = 0;
        for(int i=2; i<=n+1; i++)
            dp[i] = (((2*dp[i-1])%MOD+2)%MOD-dp[p[i-1]]+MOD)%MOD;

        System.out.println(dp[n+1]);
    }

}


/*
[ ( ^ _ ^ ) ]
*/
import java.io.*;
import java.util.*;

public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int[] p = new int[n];
        for(int i=0; i<n; i++) {
            p[i] = in.nextInt()-1;
        }
        int[] c = new int[n];
        int[] s = new int[n];
        for(int i=0; i<n; i++) {
            c[i] = 1;
            if(i>0) {
                if(p[i]==0) c[i] += s[i-1];
                else c[i] += s[i-1] - s[p[i]-1];
            }
            c[i] += 1;
            c[i] %= MOD;
            if(i>0) {
                s[i] = c[i] + s[i-1];
                s[i] %= MOD;
            } else s[i] = c[i];
        }
//        show(s);
//        show(c);
        long rs = 0;
        for(int i=0; i<n; i++) {
            rs = (rs+c[i])%MOD;
        }
        out.println(rs);
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-->0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }

    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

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

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

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

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

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


/*
[ ( ^ _ ^ ) ]
*/
import java.io.*;
import java.util.*;

public class test {
    int INF = (int)1e9;
    long MOD = 1000000007;

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int[] p = new int[n];
        for(int i=0; i<n; i++) {
            p[i] = in.nextInt()-1;
        }
        int[] c = new int[n];
        int[] s = new int[n];
        for(int i=0; i<n; i++) {
            c[i] = 1;
            if(i>0) {
                if(p[i]==0) c[i] += s[i-1];
                else c[i] += (s[i-1] - s[p[i]-1] + MOD)%MOD;
            }
            c[i] += 1;
            c[i] %= MOD;
            if(i>0) {
                s[i] = c[i] + s[i-1];
                s[i] %= MOD;
            } else s[i] = c[i];
        }
        //show(s);
        //show(c);
        long rs = 0;
        for(int i=0; i<n; i++) {
            rs = (rs+c[i])%MOD;
        }
        out.println(rs);
    }

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-->0) {
            new test().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }

    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }

    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;

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

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

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

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

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


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

public class Main {
    static final int UNCALC = -1, mod = (int) (1e9 + 7);
    static int[] memo, p;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        p = sc.nextIntArray(n);
        memo = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            memo[i] = (2 + memo[i - 1] + memo[i - 1] - memo[p[i - 1] - 1]) % mod;
            while (memo[i] < 0) memo[i] += mod;
        }
        out.println(memo[n]);
        out.close();
        out.flush();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res1 = 0, res2 = 0, res3;
  cin >> n;
  while(n--){
    int a, b;
    cin >> a >> b;
    res1 -= a;
    res2 +=(res1 + b);
    res3 = max(res3, res2);

  }
  cout << res3;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res1 = 0, res2 = 0, res3 = -10000;
  cin >> n;
  while(n!=0){
    int a, b;
    cin >> a >> b;

    res1 -= a;
    res2 +=(res1 + b);
    res3 = max(res3, res2);
    n--;
  }
  cout << res3;
}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1],l;
    max=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0]))
          {

                l=a[i][1];
                if(l>max)
                max=l;

         }

         else{

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>max)
        max=k;

    if(k==0)
    {
        cout<<max;
        break;
    }
        }}
    }}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max=0,r,i,count=0,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    int l=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0])&&i<(n-1))
          {

                l=a[i][1];
                if(l>max)
                max=l;
                r=1;

         }

         else{
           r=0;

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count<<endl;
        break;
    }
        }}
    }

    if(r==1)
        cout<<max;

    }


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    max=1;

    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
           if(a[i][j])

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>max)
        max=k;

    if(k==0)
    {
        cout<<max;
        break;
    }
        }}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max=0,r,i,count=0,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    int l=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0])&&i<(n-1))
          {

                l=a[i][1];
                if(l>max)
                max=l;

         }

         else
            {
           if(i==n-1)
           {

            r=1;
            cout<<max;
           break;}

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count<<endl;
        break;
    }
        }}
    }

    }


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1],l;
    max=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0]))
          {

                l=a[i][1];
                if(l>max)
                max=l;
         }
    }

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>max)
        max=k;

    if(k==0)
    {
        cout<<max;
        break;
    }
        }}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    max=a[0][1];

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>max)
        max=k;

    if(k==0)
    {
        cout<<max;
        break;
    }
        }}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max,r,i,count=0,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1],l;
    max=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0]))
          {

                l=a[i][1];
                if(l>max)
                max=l;
                r=1;

         }

         else{

r=0;

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count;
        break;
    }
        }}
    }
    if(r==1)
        cout<<max;

    }


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    max=1;

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>max)
        max=k;

    if(k==0)
    {
        cout<<max;
        break;
    }
        }}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max=0,r,i,count=0,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    int l=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0])&&i<(n-1))
          {

                l=a[i][1];
                if(l>max)
                max=l;

         }

         else
            {
           if(i==n-1)
           {

            r=1;
           break;}

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count<<endl;
        break;
    }
        }}
    }

    if(r==1)
        cout<<max;

    }


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max=0,r,i,count=0,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    int l=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0])&&i<(n-1))
          {

                l=a[i][1];
                if(l>max)
                max=l;

         }

         else

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count<<endl;
        break;
    }
        }}
    }

    }


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
char a[101];
cin>>a;
int k,i,r=0;

k=strlen(a);

for(i=0;i<k;i++)
{
    if(a[i]=='H'||a[i]=='9'||a[i]=='Q')
       {

        r=1;
break;}

}

if(r==1)
    cout<<"YES";
else
    cout<<"NO";
}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max=0,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>max)
        max=k;

    if(k==0)
    {
        cout<<max;
        break;
    }
        }}


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,max=0,r,i,count=0,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    int k =a[0][1];
    int l=0;

    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0])&&i<(n-1))
          {

                l=a[i][1];
                if(l>max)
                max=l;
                r=1;

         }

         else
            {
           if(i==n-1)
           {

            r=1;
           break;}

    for(i=0;i<n;i++)
    {

    k=k-a[i+1][0]+a[i+1][1];

    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count<<endl;
        break;
    }
        }}
    }

    if(r==1)
        cout<<max;

    }


#include<iostream>
#include<conio.h>
#include<cstring>
using namespace std;
int main()
{
    int n,count=0,r,s,t,k,i,j;
    cin>>n;

    int a[1000][2];
    for(i=0;i<n;i++)
    {

        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }

    }

    //int k =a[0][1];
    //int l=0;

/*
    for(i=0;i<n;i++)
    {

            if((a[i][1])==(a[i+1][0])&&i<(n-1))
          {

                l=a[i][1];
                if(l>max)
                max=l;

         }

         else
            {
           if(i==n-1)
           {

            r=1;
            cout<<max;
           break;}
*/
   k=a[0][1];
    for(i=0;i<n-1;i++)
    {

    r=a[i][1];
    k=k-a[i+1][0]+a[i+1][1];

    t=max(r,k);

    if(t>count)
        count=t;
        }

    cout<<count;
            }

/*
    if(k>count)
        count=k;

    if(k==0)
    {
        cout<<count<<endl;
        break;
    }
        */


#include<iostream>
using namespace std;
int main()
{
	int a[100], sum = 0, n, max = 0;
	cin >> n;
	for (size_t i = 0; i < n*2; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < n; i+=2)
	{

		sum = a[i + 1] - a[i + 2] + a[i + 3];
		if (sum > max)max = sum;
	}
	cout << max << "\n";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[100], sum = 0, n, max = 0;
	cin >> n;
	for (size_t i = 0; i < n*2; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < n*2; i+=2)
	{

		sum += a[i + 1];
		if (sum > max)max = sum;
		sum -= a[i + 2];
		if (i == n - 3)break;
	}
	cout << max << "\n";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[100], sum = 0, n, max = 0;
	cin >> n;
	for (size_t i = 0; i < n*2; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < n*2; i+=2)
	{

		sum += a[i + 1];
		if (sum > max)max = sum;
		sum -= a[i + 2];

	}
	cout << max << "\n";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[100], sum = 0, n, max = 0;
	cin >> n;
	for (size_t i = 0; i < n*2; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < n*2; i+=2)
	{
		if (a[i + 1] == 0)continue;
		else
		{
			sum += a[i + 1];
			if (sum > max)max = sum;
			sum -= a[i + 2];
		}
	}
	cout << max << "\n";
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[1000][2], sum = 0, n, max = 0;
	cin >> n;
	for (size_t i = 0; i < n ; i++)
	{
		for (size_t j = 0; j < 2; j++ )
		{
			cin >> a[i][j];
			if (j == 0)
			{
				sum -= a[i][0];
			}
			if (j == 1)sum += a[i][1];
			if (sum > max)max = sum;

		}

	}

	cout << max << "\n";

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[100], sum = 0, n, max = 0;
	cin >> n;
	for (size_t i = 0; i < n*2; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < n*2; i+=2)
	{
		if (a[i + 1] == 0&&a[i+2]==0)continue;
		else
		{
			sum += a[i + 1];
			if (sum > max)max = sum;
			sum -= a[i + 2];
		}
	}
	cout << max << "\n";
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a,b;
                       if(i=0)
                       {
                           s=b;
                           max=b;
                       }
                       else
                       {

                           s=s-a+b;
                           max=s>max?s:max;
                       }
                       cout<<max;

           }


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max1=0,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a,b;
                       if(i=0)
                       {
                           s=b;
                           max1=b;
                       }
                       else
                       {

                           s=s-a+b;
                          max1=max(s,max1);
                       }

           }
                cout<<max1;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a[n][2];
            for(int i=0;i<n;i++)
           {
                       for(int j=0;i<2;j++)
                       cin>>a[i][j];
           }

           int max=0;
           for(int i=0;i<n;i++)
           {
                       int s=a[i][0]-a[i][1];
                       max=s>max?s:max;
           }
           cout<<max;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max1=0,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a,b;
                       if(i=0)
                       {
                           s=b;
                           max1=b;
                       }
                       else
                       {

                           s=s-a+b;
                          max1=max(s,max1);
                       }
                       cout<<max1;
           }
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max1=0,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a,b;
                       if(i=0)
                       {
                           s=b;
                           max1=b;
                       }
                       else
                       {

                           s=s-a+b;
                           max1=s>max1?s:max1;
                       }
                       cout<<max1;
           }
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a,b;
                       if(i=0)
                       {
                           s=b;
                           max=b;
                       }
                       else
                       {

                           s=s-a+b;
                           max=s>max?s:max;
                       }
                       cout<<max;
           }
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max1=0,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a>>b;
                       if(i==0)
                       {
                           s=b;
                           max1=b;
                       }
                       else
                       {

                           s=s-a+b;
                          max1=max(s,max1);
                       }

           }
                cout<<max1;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
            int n;
            cin>>n;
            int a,b,max,s;
            for(int i=0;i<n;i++)
           {

                       cin>>a,b;
                       if(i=0)
                       {
                           s=b;
                           max=b;
                       }
                       else
                       {

                           s=s-a+b;
                           max=s>max?s:max;
                       }

           }
           cout<<max;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;

int main()
{
   int n;
   cin>>n;
   int a[n],b[n],arr[n];
   arr[n]={0};
   for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
   }
   int ans,k=0;
   for(int i=0;i<n;i++){
      ans=b[i]-a[i]+arr[i];
      arr[i]=ans;

   }
   int max = 0;
   for(int i=0;i<n;i++){
      if(arr[i]>max){
         max=arr[i];
      }
   }
   cout<<max<<endl;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;

int main()
{
   int n;
   cin>>n;
   int a[n],b[n];
   for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
   }
   int ans,k=0,maxx=-999;
   for(int i=0;i<n;i++){
      ans=b[i]-a[i]+k;
      k=ans;
      if(ans>maxx){
         maxx=ans;
      }

   }

   cout<<maxx<<endl;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main()
{
   int n;
   cin>>n;
   int a[n],b[n],arr[n];
   arr[n]={0};
   for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
   }
   for(int i=0;i<n;i++){
      arr[i] = arr[i]-a[i];
      arr[i] = arr[i]+b[i];
   }
   cout<<max(arr,arr+n)<<endl;
}