public class Main {
//System.setIn(new FileInputStream("input.txt"));
//System.setOut(new PrintStream("output.txt"));
StdIn in = new StdIn();
int n = in.nextInt();
MyStack st = new MyStack();
while (n-- > 0) {
int x = in.nextInt();
if (st.isEmpty() || st.peek() != x) {
st.push(x);
}
}
int m = in.nextInt();
int rank = st.size();
while (m-- > 0) {
int x = in.nextInt();
while (!st.isEmpty() && st.peek() <= x) {
st.pop();
--rank;
}
st.push(x);
}
}
static class MyStack {
private int capacity;
private int[] data;
private int top;
public MyStack() {
data = new int[capacity = 4];
top = 0;
}
public int size() { return top; }
public boolean isEmpty() { return size() == 0; }
public void push(int x) {
if (top + 1 >= capacity) grow();
data[++top] = x;
}
public int peek() { return data[top]; }
public int pop() { return data[top--]; }
private void grow() {
int[] temp = new int[capacity <<= 1];
System.
arraycopy(data,
0, temp,
0, top
+ 1); data = temp;
}
}
static class StdIn {
final private int BUFFER_SIZE = 1 << 21;
private byte[] buffer;
private int bufferPointer, bytesRead;
public StdIn() {
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
int c;
while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
;
StrBuilder s = new StrBuilder();
while (c != -1) {
if (c == ' ' || c == '\n' || c == '\r')
break;
s.append((char) c);
c = read();
}
return s.toStr();
}
int c;
while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'));
return (char)c;
}
int c;
while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
;
StrBuilder s = new StrBuilder();
while (c != -1) {
if (c == '\n' || c == '\r')
break;
s.append((char) c);
c = read();
}
return s.toStr();
}
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 int[] readIntArray
(int n
) throws Exception { int[] ar = new int[n];
for (int i = 0; i < n; ++i)
ar[i] = nextInt();
return ar;
}
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 long[] readLongArray
(int n
) throws Exception { long[] ar = new long[n];
for (int i = 0; i < n; ++i)
ar[i] = nextLong();
return ar;
}
public double nextDouble
() throws Exception { 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;
}
bytesRead
= System.
in.
read(buffer, bufferPointer
= 0, BUFFER_SIZE
); if (bytesRead == -1)
buffer[0] = -1;
}
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
}
static class StrBuilder {
private char data[];
int n, m;
public StrBuilder() {
data = new char[m = 4];
n = 0;
}
public void append(char c) {
if(n == m) resize(m *= 2);
data[n++] = c;
}
return new String(data,
0, n
); }
private void resize(int sz) {
char tmp[] = new char[sz];
for(int i = 0; i < n; ++i) tmp[i] = data[i];
data = tmp;
}
}
}