#include<stdio.h>
#include<string.h>
#define N 200
#define infin 327670
typedef struct
{
    int vexnum,arcnum;
    int arcs[N][N];
}MGraph;
void CreatMGraph(MGraph *g);
void Dijkstra (MGraph *g,int v);
int mincost(int dist[],int set[],int n);
int main()
{
    MGraph p;
    CreatMGraph(&p);
    Dijkstra (&p,0);
	//getchar();getchar();
    return 0;
}

void CreatMGraph(MGraph *g)
{
    int i,j;
    int p=0,q=0,weight =0,a,b;
    scanf("%d%d",&a,&b);
    g->vexnum = a;
    g->arcnum = b;
    for(i=0;i<g->vexnum;i++)
    {
        for(j=0;j<g->vexnum;j++)
        {
            g->arcs[i][j] = infin;
        }
    }
	for(i=0;i<g->arcnum;i++)
	{
		scanf("%d%d",&p,&q);
		g->arcs[p-1][q-1] = 1;
		g->arcs[q-1][p-1] = 1;
	}
    
    

}
void Dijkstra (MGraph *g,int v)
{
    int set[N],dist[N];
    int i,j,w,sum,k = 0;
    for(i = 0;i<g->vexnum;i++)
    {
        dist[i] = g->arcs[v][i];
        set[i] = 0;
    }
    set[v] = ++k;
    for(i =1;i<g->vexnum;i++)
    {
        w = mincost(dist,set,g->vexnum);
        set[w] = ++k;
        for(j=0;j<g->vexnum;j++)
            if(set[j] == 0)
            {
                sum = dist[w] + g->arcs[w][j];
                dist[j] = (dist[j] < sum) ? dist[j]:sum;
            }
    }
    for(j=0;j<g->vexnum;j++)
    {
        if(dist[j] ==  infin)
            printf("Yes\n");
        else
            printf("%d\n",dist[j]);
    }

}
int mincost(int dist[],int set[],int n)
{
    int i,tmp= infin,w =2;
    for(i=0;i<n;i++)
    {
        if((set[i]==0) && (dist[i])<tmp)
        {
            tmp = dist[i];
            w =i;
        }
    }
    return (w);
}

