#include #include #include #include #include #include #define LL long long #define Re register int using namespace std; const int N=103,M=40000,inf=2e9; int x,y,o=1,n,m,h,t,st,ed,flag,cyf[N],pan[N],pre[N],dis[N],head[N];LL maxcost,maxflow; struct QAQ{int w,to,next,flow;}a[M<<1];queueQ;string CH,ch[N];mapip; inline void add(Re x,Re y,Re z,Re w){a[++o].flow=z,a[o].w=w,a[o].to=y,a[o].next=head[x],head[x]=o;} inline void add_(Re a,Re b,Re flow,Re w){add(a,b,flow,w),add(b,a,0,-w);} inline int SPFA(Re st,Re ed){ for(Re i=0;i<=ed;++i)dis[i]=-inf,pan[i]=0; Q.push(st),pan[st]=1,dis[st]=0,cyf[st]=inf; while(!Q.empty()){ Re x=Q.front();Q.pop();pan[x]=0; for(Re i=head[x],to;i;i=a[i].next) if(a[i].flow&&dis[to=a[i].to]>n>>m;st=1,ed=n<<1; for(Re i=1;i<=n;++i)cin>>ch[i],ip[ch[i]]=i; for(Re i=2;i>CH;x=ip[CH]; cin>>CH;y=ip[CH]; if(x>y)swap(x,y); flag|=x==1&&y==n; add_(x+n,y,1,0); } EK(st,ed); if(maxflow==2)printf("%d\n",maxcost-2); else if(maxflow==1&&flag){ printf("2\n"); cout<