public class Main {
static int[] unf;
static int find(int v){
if(v == unf[v])
return v;
else
return unf[v] = find(unf[v]);
}
static void union(int a, int b){
int fa = find(a);
int fb = find(b);
if(fa != fb)
unf[fa] = fb;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
unf = new int[n+1];
for(int i=1; i<=n; ++i)
unf[i] = i;
int m = sc.nextInt();
for(int i=1; i<=n; ++i){
for(int j=1; j<=n; ++j){
if(sc.nextInt() == 1) {
union(i,j);
}
}
}
String answer = "YES";
int first = sc.nextInt();
for(int i=0; i<m-1; ++i)
if(find(sc.nextInt()) != find(first))
answer = "NO";
System.out.println(answer);
}
}