package test;
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 BaekJoonQ1976 {
static BufferedWriter bw;
static int id[] = null;
static int root(int node) {
while (id[node] != node) {
id[node] = id[id[node]];
node = id[node];
}
return node;
}
static void union(int firstNode, int secNode) {
int valueFirst = root(firstNode);
int valueSec = root(secNode);
if (valueFirst != valueSec) {
id[valueFirst] = valueSec;
}
}
static boolean isConnected(int firstNode, int secNode) {
return root(firstNode) == root(secNode);
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int city = Integer.parseInt(br.readLine());
int plan = Integer.parseInt(br.readLine());
id = new int[city + 1];
for(int i=0;i<=city;i++) {
id[i] =i;
}
for (int i = 1; i <= city; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 1; j <= city; j++) {
int connection = Integer.parseInt(st.nextToken());
if (connection == 1) {
union(i, j);
}
}
}
st = new StringTokenizer(br.readLine());
int trip = Integer.parseInt(st.nextToken());
boolean flag = true;
for (int i = 1; i < plan; i++) {
flag = flag && isConnected(trip, Integer.parseInt(st.nextToken()));
}
bw.write(flag ? "YES" : "NO");
bw.flush();
}
}