// CSP202212-2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int[] p = new int[m + 1];
p[0] = 0;
int i = 1;
while (i < m + 1) {
p[i] = scan.nextInt();
i++;
}
int[] t = new int[m + 1];
t[0] = 0;
i = 1;
while (i < m + 1) {
t[i] = scan.nextInt();
i++;
}
int[] earliest = new int[m + 1];
earliest[0] = 0;
int flag = 1; // 1:able to finish in time
i = 1;
while (i < m + 1) {
if (p[i] == 0)
earliest[i] = 1;
else {
earliest[i] = earliest[p[i]] + t[p[i]];
}
if (earliest[i] + t[i] - 1 > n)
flag = 0;
i++;
}
for (i = 1; i < earliest.length; i++) {
System.out.print(earliest[i]);
if (i < earliest.length - 1) {
System.out.print(" ");
} else {
System.out.println();
}
}
if (flag == 1) {
int[] latest = new int[m + 1];
for (i = 0; i < latest.length; i++) {
latest[i] = n;
}
i = m;
while (i > 0) {
if (i == m) {
latest[i] = n + 1 - t[i];
}
latest[i] = Math.min(n + 1 - t[i], latest[i]);
if (p[i] != 0) {
latest[p[i]] = Math.min(latest[i] - t[p[i]], latest[p[i]]);
}
i--;
}
for (i = 1; i < latest.length; i++) {
System.out.print(latest[i]);
if (i < latest.length - 1) {
System.out.print(" ");
} else {
System.out.println();
}
}
}
}
}