#include <bits/stdc++.h>
using namespace std;

class Graph
{
  int V;
  list<int> *adj;
  void DFSUtil(int v, bool visited[]);

public:
  Graph(int V);
  void addEdge(int v, int w);
  void DFS(int v);
};

Graph::Graph(int V)
{
  this->V = V;
  adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
  adj[v].push_back(w);
}

void Graph::DFSUtil(int v, bool visited[])
{
  visited[v] = true;
  cout << v << " ";
  adj[v].unique();
  adj[v].sort();
  for (auto i : adj[v])
  {
    if (!visited[i])
      DFSUtil(i, visited);
  }
}
void Graph::DFS(int v)
{
  bool *visited = new bool[V + 1];
  for (int i = 0; i <= V; i++)
    visited[i] = false;
  DFSUtil(v, visited);
}

main()
{
  int n, m, u1, v1, u, v;
  cin >> n >> m;
  Graph g(n + 1);

  for (int i = 0; i < m; i++)
  {
    cin >> u >> v;
    g.addEdge(u, v);
    g.addEdge(v, u);
  }
  g.DFS(1);
}


#include <bits/stdc++.h>
using namespace std;

class Graph
{
  int V;
  list<int> *adj;
  void DFSUtil(int v, bool visited[]);

public:
  Graph(int V);
  void addEdge(int v, int w);
  void DFS(int v);
};

Graph::Graph(int V)
{
  this->V = V;
  adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
  adj[v].push_back(w);
}

void Graph::DFSUtil(int v, bool visited[])
{
  visited[v] = true;
  cout << v << " ";
  list<int>::iterator i;
  adj[v].sort();
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
  {
    if (!visited[*i])
      DFSUtil(*i, visited);
  }
}
void Graph::DFS(int v)
{
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++)
    visited[i] = false;
  DFSUtil(v, visited);
}

main()
{
  int n, m, u1, v1, u, v;
  cin >> n >> m;
  Graph g(n + 1);
  cin >> u1 >> v1;
  g.addEdge(u1, v1);
  g.addEdge(v1, u1);
  for (int i = 2; i <= m; i++)
  {
    cin >> u >> v;
    g.addEdge(u, v);
    g.addEdge(v, u);
  }
  g.DFS(1);
}


#include <bits/stdc++.h>
using namespace std;

class Graph
{
  int V;
  list<int> *adj;
  void DFSUtil(int v, bool visited[]);

public:
  Graph(int V);
  void addEdge(int v, int w);
  void DFS(int v);
};

Graph::Graph(int V)
{
  this->V = V;
  adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
  adj[v].push_back(w);
}

void Graph::DFSUtil(int v, bool visited[])
{
  visited[v] = true;
  cout << v << " ";
  list<int>::iterator i;
  adj[v].sort();
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
  {
    if (!visited[*i])
      DFSUtil(*i, visited);
  }
  i = adj[v].end();
  if (!visited[*i])
    DFSUtil(*i, visited);
}
void Graph::DFS(int v)
{
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++)
    visited[i] = false;
  DFSUtil(v, visited);
}

main()
{
  int n, m, u1, v1, u, v;
  cin >> n >> m;
  Graph g(n + 1);
  cin >> u1 >> v1;
  g.addEdge(u1, v1);
  g.addEdge(v1, u1);
  for (int i = 2; i <= m; i++)
  {
    cin >> u >> v;
    g.addEdge(u, v);
    g.addEdge(v, u);
  }
  g.DFS(u1);
}


#include <bits/stdc++.h>
using namespace std;

class Graph
{
  int V;
  list<int> *adj;
  void DFSUtil(int v, bool visited[]);

public:
  Graph(int V);
  void addEdge(int v, int w);
  void DFS(int v);
};

Graph::Graph(int V)
{
  this->V = V;
  adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
  adj[v].push_back(w);
}

void Graph::DFSUtil(int v, bool visited[])
{
  visited[v] = true;
  cout << "\n" << v << "\n";
  adj[v].unique();
  adj[v].sort();
  cout << "{";
  for (auto i : adj[v])
  {
    cout << i << " ";
    if (!visited[i])
      DFSUtil(i, visited);
  }
}
void Graph::DFS(int v)
{
  bool *visited = new bool[V + 1];
  for (int i = 0; i <= V; i++)
    visited[i] = false;
  DFSUtil(v, visited);
}

main()
{
  int n, m, u1, v1, u, v;
  cin >> n >> m;
  Graph g(n + 1);

  for (int i = 0; i < m; i++)
  {
    cin >> u >> v;
    g.addEdge(u, v);
    g.addEdge(v, u);
  }
  g.DFS(1);
}


#include <bits/stdc++.h>
using namespace std;

class Graph
{
  int V;
  list<int> *adj;
  void DFSUtil(int v, bool visited[]);

public:
  Graph(int V);
  void addEdge(int v, int w);
  void DFS(int v);
};

Graph::Graph(int V)
{
  this->V = V;
  adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
  adj[v].push_back(w);
}

void Graph::DFSUtil(int v, bool visited[])
{
  visited[v] = true;
  cout << v << " ";
  adj[v].unique();
  adj[v].sort();
  for (auto i : adj[v])
  {
    if (!visited[i])
      DFSUtil(i, visited);
  }
}
void Graph::DFS(int v)
{
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++)
    visited[i] = false;
  DFSUtil(v, visited);
}

main()
{
  int n, m, u1, v1, u, v;
  cin >> n >> m;
  Graph g(n + 1);

  for (int i = 0; i < m; i++)
  {
    cin >> u >> v;
    g.addEdge(u, v);
    g.addEdge(v, u);
  }
  g.DFS(1);
}


#include <bits/stdc++.h>

using namespace std;

#define N 100000

int n, m, id, output[N];
vector<int> vertex[N];
set<int> sad;
bool flag[N];

void printSet();
void readInput();

int main()
{
  readInput();
  output[0] = 1;
  flag[1] = true;
  for (auto y : vertex[1])
  {
    if (!flag[y])
    {
      sad.insert(y);
    }
  }
  id = 0;
  while (id < n)
  {
    int temp = *sad.begin();
    sad.erase(temp);
    output[++id] = temp;
    flag[temp] = true;
    for (auto y : vertex[temp])
      if (!flag[y])
        sad.insert(y);
  }
  for (int i = 0; i < n; ++i)
  {
    cout << output[i];
    if (i != n - 1)
      cout << " ";
  }
  return 0;
}

void printSet()
{
  cout << "___";
  for (auto s : sad)
  {
    cout << s << " ";
  }
  cout << "___" << endl;
}

void readInput()
{
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; ++i)
  {
    cin >> u >> v;
    vertex[u].push_back(v);
    vertex[v].push_back(u);

  }
  system("cls");
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define size1 1e6

void DFS(int s, vector<vector<int> > &edge, vector<int> &result, vector<int> &visited){
    priority_queue <int, vector<int>, greater<int> > qu;

    qu.push(s);
    visited[s] = 1;

    while(!qu.empty()){

        int u = qu.top();
        result.push_back(u);

        qu.pop();

        for(int i = 0; i < edge[u].size(); i++){
            int v = edge[u][i];

            if(!visited[v]){
                visited[v] = 1;
                qu.push(v);
            }

        }
    }

    for(int i = 0; i < result.size(); i++) cout << result[i] << " ";

}

int main(){
    int n, m; cin >> n >> m;

    vector<vector<int> > edge(size1);
    vector<int> result;
    vector<int> visited(size1), ans[1000];
    ll tc, t = 1;

    int mx1 = max(n, m);

    for(ll j=0; j<m; j++){
        int first, last;
        cin >> first >> last;

        edge[first].push_back(last);
        edge[last].push_back(first);
    }

    DFS(1, edge, result, visited);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> graph;

void DFS(int s, graph &edge, vi &result, vi &visited){
    priority_queue <int, vector<int>, greater<int> > qu;

    qu.push(s);
    visited[s] = 1;

    while(!qu.empty()){

        int u = qu.top();
        result.push_back(u);

        qu.pop();

        for(int i = 0; i < edge[u].size(); i++){
            int v = edge[u][i];

            if(!visited[v]){
                visited[v] = 1;
                qu.push(v);
            }

        }
    }

    for(int i = 0; i < result.size(); i++) cout << result[i] << " ";

}

int main(){
    int n, m; cin >> n >> m;

    graph edge(1e6);
    vi result;
    vi visited(1e6), ans[1000];

    int mx1 = max(n, m);

    for(int j=0; j<m; j++){
        int first, last;
        cin >> first >> last;

        edge[first].push_back(last);
        edge[last].push_back(first);
    }

    DFS(1, edge, result, visited);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define size1 1e6

void DFS(int s, vector<vector<int> > &edge, vector<int> &result, vector<int> &visited){
    priority_queue <int, vector<int>, greater<int> > qu;

    qu.push(s);
    visited[s] = 1;

    while(!qu.empty()){

        int u = qu.top();
        result.push_back(u);

        qu.pop();

        for(int i = 0; i < edge[u].size(); i++){
            int v = edge[u][i];

            if(!visited[v]){
                visited[v] = 1;
                qu.push(v);
            }

        }
    }

    for(int i = 0; i < result.size(); i++) cout << result[i] << " ";

}

int main(){
    int n, m; cin >> n >> m;

    vector<vector<int> > edge(size1);
    vector<int> result;
    vector<int> visited(size1), ans[1000];
    ll tc, t = 1;

    int mx1 = max(n, m);

    for(int j=0; j<m; j++){
        int first, last;
        cin >> first >> last;

        edge[first].push_back(last);
        edge[last].push_back(first);
    }

    DFS(1, edge, result, visited);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> graph;

void DFS(int s, graph &M, vi &visited, vi &p){
    visited[s] = 1;
    priority_queue <int, vi, greater<int> > pq;
    pq.push(s);

    while(!pq.empty()){
        int front = pq.top(); pq.pop();
        p.push_back(front);

        for(int j = 0; j < M[front].size(); j++){
            int u = M[front][j];
            if(!visited[u]){
                visited[u] = 1;
                pq.push(u);
            }

        }
    }
}

int main(){
    int n, m; cin >> n >> m;
    graph G(1e6);
    vi visited(1e6, 0);
    vi p;

    int u, v;
    for(int j=0; j<m; j++){
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    DFS(1, G, visited, p);
    for(int i=0; i<p.size(); i++) cout << p[i] << " ";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

void DFS(int s, vector<vector<int> > &edge, vector<int> &result, vector<int> &visited){
    priority_queue <int, vector<int>, greater<int> > qu;

    qu.push(s);
    visited[s] = 1;

    while(!qu.empty()){

        int u = qu.top();
        result.push_back(u);

        qu.pop();

        for(int i = 0; i < edge[u].size(); i++){
            int v = edge[u][i];

            if(!visited[v]){
                visited[v] = 1;
                qu.push(v);
            }

        }
    }

    for(int i = 0; i < result.size(); i++) cout << result[i] << " ";

}

int main(){
    int n, m; cin >> n >> m;

    vector<vector<int> > edge(1e6);
    vector<int> result;
    vector<int> visited(1e6), ans[1000];

    int mx1 = max(n, m);

    for(int j=0; j<m; j++){
        int first, last;
        cin >> first >> last;

        edge[first].push_back(last);
        edge[last].push_back(first);
    }

    DFS(1, edge, result, visited);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> graph;

void DFS(int s, graph &G, vi &visited, vi &p){
    visited[s] = 1;
    priority_queue <int, vi, greater<int> > pq;
    pq.push(s);

    while(!pq.empty()){
        int front = pq.top(); pq.pop();
        p.push_back(front);

        for(int j = 0; j < G[front].size(); j++){
            int u = G[front][j];
            if(!visited[u]){
                visited[u] = 1;
                pq.push(u);
            }

        }
    }
}

int main(){
    int n, m; cin >> n >> m;
    graph G(1e6);
    vi visited(1e6, 0);
    vi p;

    int u, v;
    for(int j=0; j<m; j++){
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    DFS(1, G, visited, p);
    for(int i = 0; i < p.size(); i++) cout << p[i] << " ";

    return 0;
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=2e6+30;
vector<int>adj[nax];
vector<bool>visited(nax,0);
vector<int>ans;
void dfs(int u)
{
    visited[u]=1;
    ans.push_back(u);
    for(int i:adj[u])
    {
        if(!visited[i])
            dfs(i);
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
//    dfs(0);
    priority_queue<int,vector<int>,greater<int>>pq;
    pq.push(0);
    while(!pq.empty())
    {
        int tp=pq.top();
        pq.pop();
        if(find(ans.begin(),ans.end(),tp+1)==ans.end())
        ans.push_back(tp+1);
        visited[tp]=1;
        for(int i:adj[tp])
        {
            if(!visited[i])
                pq.push(i);
        }
    }
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" ";
    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=1e5+10;
vector<int>adj[nax];
vector<bool>visited(nax,0);
//vector<int>ans;
void dfs(int u)
{
    visited[u]=1;
    ans.push_back(u);
    for(int i:adj[u])
    {
        if(!visited[i])
            dfs(i);
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
    map<int,int>mp;
//    dfs(0);
    priority_queue<int,vector<int>,greater<int>>pq;
    pq.push(0);
    while(!pq.empty())
    {
        int tp=pq.top();
        pq.pop();
        if(mp[tp+1]==0)
        {
            cout<<tp+1<<" ";
        }
//        ans.push_back(tp+1);
        mp[tp+1]=1;
        visited[tp]=1;
        for(int i:adj[tp])
        {
            if(!visited[i])
                pq.push(i);
        }
    }
//    for(int i=0;i<ans.size();i++)
//        cout<<ans[i]<<" ";
//    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=1e5+10;
vector<int>adj[nax];
vector<bool>visited(nax,0);
//vector<int>ans;
//void dfs(int u)
//{
//    visited[u]=1;
//    ans.push_back(u);
//    for(int i:adj[u])
//    {
//        if(!visited[i])
//            dfs(i);
//    }
//}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
//    map<int,int>mp;
//    dfs(0);
//    priority_queue<int,vector<int>,greater<int>>pq;
    set<int>pq;
    pq.insert(0);
    while(!pq.empty())
    {
        int tp=*pq.begin();
        pq.erase(pq.begin());
//        if(mp[tp+1]==0)
//        {
            cout<<tp+1<<" ";
//        }
//        ans.push_back(tp+1);
//        mp[tp+1]=1;
        visited[tp]=1;
        for(int i:adj[tp])
        {
            if(!visited[i])
                pq.insert(i);
        }
    }
//    for(int i=0;i<ans.size();i++)
//        cout<<ans[i]<<" ";
//    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=2e6+30;
vector<int>adj[nax];
vector<bool>visited(nax,0);
vector<int>ans;
void dfs(int u)
{
    visited[u]=1;
    ans.push_back(u);
    for(int i:adj[u])
    {
        if(!visited[i])
            dfs(i);
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
    dfs(0);
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]+1<<" ";
    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=1e5+10;
vector<int>adj[nax];
vector<bool>visited(nax,0);
//vector<int>ans;
//void dfs(int u)
//{
//    visited[u]=1;
//    ans.push_back(u);
//    for(int i:adj[u])
//    {
//        if(!visited[i])
//            dfs(i);
//    }
//}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
    map<int,int>mp;
//    dfs(0);
    priority_queue<int,vector<int>,greater<int>>pq;
    pq.push(0);
    while(!pq.empty())
    {
        int tp=pq.top();
        pq.pop();
        if(mp[tp+1]==0)
        {
            cout<<tp+1<<" ";
        }
//        ans.push_back(tp+1);
        mp[tp+1]=1;
        visited[tp]=1;
        for(int i:adj[tp])
        {
            if(!visited[i])
                pq.push(i);
        }
    }
//    for(int i=0;i<ans.size();i++)
//        cout<<ans[i]<<" ";
//    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=1e5+10;
vector<int>adj[nax];
vector<bool>visited(nax,0);
vector<int>ans;
void dfs(int u)
{
    visited[u]=1;
    ans.push_back(u);
    for(int i:adj[u])
    {
        if(!visited[i])
            dfs(i);
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
    map<int,int>mp;
//    dfs(0);
    priority_queue<int,vector<int>,greater<int>>pq;
    pq.push(0);
    while(!pq.empty())
    {
        int tp=pq.top();
        pq.pop();
        if(mp[tp+1]==0)
        ans.push_back(tp+1);
        mp[tp+1]=1;
        visited[tp]=1;
        for(int i:adj[tp])
        {
            if(!visited[i])
                pq.push(i);
        }
    }
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" ";
    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


//
// Created by rajshah9914 on 20/04/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pp;
ll prime[2000000];
ll M=1000000007;
void boost() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void sieve(ll ending)
{
    for(ll i=2;i<ending;i++)
        prime[i]=1;
    for(int i=2;i*i<=ending;i++)
    {
        if(prime[i]==1)
        {
            for(int j=2*i;j<=ending;j=j+i)
            {
                prime[j]=0;
            }
        }
    }
    prime[1]=0;
}

ll ncrmodp(ll num,ll r)
{
    ll C[r+1];
    ll i,j;
    memset(C,0,sizeof(C));
    C[0]=1;
    for(i=1;i<=num;i++)
    {
        for(j=min(i,r);j>0;j--)
        {
            C[j]=((C[j])%M+(C[j-1])%M)%M;
        }
    }
    return C[r];
}

ll power(ll x,ll y)
{
    ll res = 1;
    x = x % M;
    if(x==0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % M;

        y = y>>1; // y = y/2
        x = (x*x) % M;
    }
    return res;
}
const ll nax=2e6+30;
vector<int>adj[nax];
vector<bool>visited(nax,0);
vector<int>ans;
void dfs(int u)
{
    visited[u]=1;
    ans.push_back(u);
    for(int i:adj[u])
    {
        if(!visited[i])
            dfs(i);
    }
}

void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v,u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<n;i++)
    {
        sort(adj[i].begin(),adj[i].end());
    }
    map<int,int>mp;
//    dfs(0);
    priority_queue<int,vector<int>,greater<int>>pq;
    pq.push(0);
    while(!pq.empty())
    {
        int tp=pq.top();
        pq.pop();
        if(mp[tp+1]==0)
        ans.push_back(tp+1);
        mp[tp+1]=1;
        visited[tp]=1;
        for(int i:adj[tp])
        {
            if(!visited[i])
                pq.push(i);
        }
    }
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" ";
    cout<<endl;
}

int main()
{
    boost();
//    int t;
//    cin>>t;
//    while(t--)
        solve();
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
priority_queue<int ,vector<int>, greater<int> > mp[maxn];

int ans[maxn];
int v;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[v++]=x;
    if(v==n)return ;
    while(!mp[x].empty()){
        int u = mp[x].top();
        mp[x].pop();
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;

    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push(v);
        mp[v].push(u);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=0;i<v;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
priority_queue<int ,vector<int>, greater<int> > mp[maxn];

int ans[maxn];
int v;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[v++]=x;
    if(v==n)return ;
    while(!mp[x].empty()){
        int u = mp[x].top();
        mp[x].pop();
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;

    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push(v);
        mp[v].push(u);
    }
    dfs(1);
    for(int i=0;i<v;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
priority_queue<int ,vector<int>, greater<int> > mp[maxn];

int ans[maxn];
int vv;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[vv++]=x;
    if(vv==n)return ;
    while(!mp[x].empty()){
        int u = mp[x].top();
        mp[x].pop();
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;

    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push(v);
        mp[v].push(u);
    }
    dfs(1);
    for(int i=0;i<vv;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
vector<int> mp[maxn];

int ans[maxn];
int v;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[v++]=x;
    if(v==n)return ;
    for(int i=0;i<mp[x].size();i++){
        int u = mp[x][i];
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;

    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push_back(v);
        mp[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=0;i<v;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
priority_queue<int ,vector<int>, greater<int> > mp[maxn];

int ans[maxn];
int vv;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[vv++]=x;
    if(vv==n)return ;
    while(!mp[x].empty()){
        int u = mp[x].top();
        mp[x].pop();
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;

    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push(v);
        mp[v].push(u);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=0;i<vv;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
priority_queue<int ,vector<int>, greater<int> > mp[maxn];

int vv;
int v[maxn];

int main() {
    IO;
    cin >> n >> m;
    int a,b;
    vector<int> g[n + 1];
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> ans;
    ans.push_back(1);
    v[1] = 1;
    priority_queue<int, vector<int>, greater<int> > q;
    for (auto i : g[1]) {
        if (!v[i]) {
            q.push(i);
            v[i]++;
        }
    }
    while (!q.empty()) {
        ans.push_back(q.top());
        q.pop();
        int now = ans.back();
        for (auto i : g[now]) {
            if (v[i])
                continue;
            v[i]++;
            q.push(i);
        }
    }

    for (auto i : ans)
        cout << i <<" ";
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
vector<int> mp[maxn];

int ans[maxn];
int vv;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[vv++]=x;
    if(vv==n)return ;
    sort(mp[x].begin(),mp[x].end());
    for(int i=0;i<mp[x].size();i++){
        int u = mp[x][i];
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;
    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push_back(v);
        mp[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=0;i<vv;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
vector<int> mp[maxn];

int ans[maxn];
int v;
int vis[maxn];

void dfs(int x){
    vis[x]=1;
    ans[v++]=x;
    if(v==n)return ;
    sort(mp[x].begin(),mp[x].end());
    for(int i=0;i<mp[x].size();i++){
        int u = mp[x][i];
        if(!vis[u]){
            dfs(u);
        }
    }
}

int main(){
    IO;

    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push_back(v);
        mp[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=0;i<v;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define pi 3.141592653589793238462
#define ull unsigned long long
#define IO std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
const ll maxn = 1e5+7;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int base = 13331;
int n,m;
vector<int> mp[maxn];

int ans[maxn];
int vv;
int vis[maxn];

void dfs(int x){
    if(vis[x]==0)
    ans[vv++]=x;
    vis[x]=1;
    if(vv==n)return ;
    sort(mp[x].begin(),mp[x].end());
    for(int i=0;i<mp[x].size();i++){
        int u = mp[x][i];
        dfs(u);
    }
}

int main(){
    IO;
    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        mp[u].push_back(v);
        mp[v].push_back(u);
    }
    dfs(1);
    for(int i=0;i<vv;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<set<ll>> a(100010);
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(auto it=a[x].begin();it!=a[x].end();it++)
    {
        ll value=*it;
        if(b[value]==false)
        {
            for(auto j=a[x].begin();j!=a[x].end();j++)
            {
                ll val=*j;
                if(b[val]==false)
                a[value].insert(val);
            }
            dfs(value);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].insert(y);
        a[y].insert(x);
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef int ll;
#define pll pair<long,long>
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<set<ll>> a(100010);
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(auto it=a[x].begin();it!=a[x].end();it++)
    {
        ll value=*it;
        if(b[value]==false)
        {
            for(auto j=a[x].begin();j!=a[x].end();j++)
            {
                ll val=*j;
                if(b[val]==false)
                a[value].insert(val);
            }
            dfs(value);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].insert(y);
        a[y].insert(x);
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<ll> a[100010];
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(ll i=0;i<a[x].size();i++)
    {
        if(b[a[x][i]]==false)
        {
            dfs(a[x][i]);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    for(ll i=1;i<=n;i++)
    {
        sort(a[i].begin(),a[i].end());
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<ll> a[100010];
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(ll i=0;i<a[x].size();i++)
    {
        if(b[a[x][i]]==false)
        {
            for(ll j=0;j<a[x].size();j++)
            a[a[x][i]].pb(a[x][j]);
            sort(a[a[x][i]].begin(),a[a[x][i]].end());
            dfs(a[x][i]);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    for(ll i=1;i<=n;i++)
    {
        sort(a[i].begin(),a[i].end());
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<ll> a[100010];
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(ll i=0;i<a[x].size();i++)
    {
        if(b[a[x][i]]==false)
        {
            dfs(a[x][i]);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    for(ll i=1;i<=n;i++)
    {
        if(a[i].size()!=0)
        sort(a[i].begin(),a[i].end());
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define pll pair<long,long>
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<ll> a[100010];
bool b[100010];
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    for(ll i=1;i<=n;i++)
    {
        sort(a[i].begin(),a[i].end());
    }
    set<ll> s;
    vector<ll> ans;
    s.insert(1);
    mset(b,false);
    while(s.size())
    {
        auto it=s.begin();
        ll x=*it;
        s.erase(it);
        b[x]=true;
        ans.pb(x);
        for(ll i=0;i<a[x].size();i++)
        {
            if(b[a[x][i]]==false)
            {
                s.insert(a[x][i]);
            }
        }
    }
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<ll> a[100010];
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(ll i=0;i<a[x].size();i++)
    {
        if(b[a[x][i]]==false)
        {
            dfs(a[x][i]);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x!=y)
        {
            a[x].pb(y);
            a[y].pb(x);
        }
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    for(ll i=1;i<=n;i++)
    {
        if(a[i].size()!=0)
        sort(a[i].begin(),a[i].end());
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<ll> a[100010];
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(ll i=0;i<a[x].size();i++)
    {
        if(b[a[x][i]]==false)
        {
            for(ll j=0;j<a[x].size();j++)
            {
                if(find(a[a[x][i]].begin(),a[a[x][i]].end(),a[x][j])==a[a[x][i]].end())
                {
                a[a[x][i]].pb(a[x][j]);
                }
            }
            sort(a[a[x][i]].begin(),a[a[x][i]].end());
            dfs(a[x][i]);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    for(ll i=1;i<=n;i++)
    {
        sort(a[i].begin(),a[i].end());
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<ll> a[100010];
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(ll i=0;i<a[x].size();i++)
    {
        if(b[a[x][i]]==false)
        {
            for(ll j=0;j<a[x].size();j++)
            {
                if(find(a[a[x][i]].begin(),a[a[x][i]].end(),a[x][j])==a[i].end())
                {
                a[a[x][i]].pb(a[x][j]);
                }
            }
            sort(a[a[x][i]].begin(),a[a[x][i]].end());
            dfs(a[x][i]);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    for(ll i=1;i<=n;i++)
    {
        sort(a[i].begin(),a[i].end());
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<long,long>
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define mset(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
vector<set<ll>> a(100010);
bool b[100010];
vector<ll> ans;
void dfs(ll x)
{
    b[x]=true;
    ans.pb(x);
    for(auto it=a[x].begin();it!=a[x].end();it++)
    {
        ll value=*it;
        if(b[value]==false)
        {
            for(auto j=a[x].begin();j!=a[x].end();j++)
            {
                ll val=*j;
                a[value].insert(val);
            }
            dfs(value);
        }
    }
}
int main()
{
    FIO;
    ll n,m;
    cin>>n>>m;
    mset(b,false);
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[x].insert(y);
        a[y].insert(x);
    }
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    dfs(1);
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100000],u,v1,temp=0,a[300000];
vector<int>s[1000000];
set<int>v;
//set<int>::iterator ptr;
void dfs(int x)
{
	cout<<x<<" ";

	for(int i=0;i<s[x].size();i++)
	{
		v.insert(s[x][i]);
	}

	visited[x]=1;
	for (auto it = v.begin(); it != v.end(); it++)
	{
		int p=*it;
		if(visited[p]==0)
		dfs(p);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v1;
		if(u!=v1)
		{
		s[u].push_back(v1);
		s[v1].push_back(u);
		}
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100005],u,v1,temp=0,a[300000];
vector<int>s[100005];
set<int>v;
//set<int>::iterator ptr;
void dfs(int x)
{
	cout<<x<<" ";
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		v.insert(s[x][i]);
	}

	for (auto it = v.begin(); it != v.end(); it++)
	{
		int p=*it;
		v.erase(0);
		if(visited[p]==0)
		dfs(p);

	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v1;
		if(u!=v1)
		{
		s[u].push_back(v1);
		s[v1].push_back(u);
		}
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
			break;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100000],u,v,temp=0,a[300000];
vector<int>s[1000000];
void dfs(int x)
{
	cout<<x<<" ";
	//ram=min(a[x],ram);
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		int p=s[x][i];
		if(visited[p]==0)
		dfs(p);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v;
		s[u].push_back(v);
		s[v].push_back(u);
	}
	for(i=1;i<=y;i++)
	{
		sort(s[i].begin(), s[i].end());
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100000],u,v1,temp=0,a[300000];
vector<int>s[1000000];
set<int>v;
//set<int>::iterator ptr;
void dfs(int x)
{
	cout<<x<<" ";

	for(int i=0;i<s[x].size();i++)
	{
		v.insert(s[x][i]);
	}

	visited[x]=1;
	for (auto it = v.begin(); it != v.end(); it++)
	{
		int p=*it;
		v.erase(0);
		if(visited[p]==0)
		dfs(p);

	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v1;
		if(u!=v1)
		{
		s[u].push_back(v1);
		s[v1].push_back(u);
		}
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
			break;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100000],u,v,temp=0,a[300000];
vector<int>s[1000000];
void dfs(int x)
{
	cout<<x<<" ";
	//ram=min(a[x],ram);
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		int p=s[x][i];
		if(visited[p]==0)
		dfs(p);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v;
		if(u!=v)
		{
		s[u].push_back(v);
		s[v].push_back(u);
		}
	}
	for(i=0;i<=x;i++)
	{

		sort(s[i].begin(), s[i].end());
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100000],u,v,temp=0,a[300000];
vector<int>s[1000000];
void dfs(int x)
{
	cout<<x<<" ";
	//ram=min(a[x],ram);
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		int p=s[x][i];
		if(visited[p]==0)
		dfs(p);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v;
		if(u!=v)
		{
		s[u].push_back(v);
		s[v].push_back(u);
		}
	}
	for(i=0;i<=y;i++)
	{
		sort(s[i].begin(), s[i].end());
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100005],u,v1,temp=0,a[300000];
vector<int>s[100005];
set<int>v;
//set<int>::iterator ptr;
void dfs(int x)
{
	cout<<x<<" ";
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		v.insert(s[x][i]);
	}

	while(1)
	{
		auto it = v.begin();
		int p=*it;
		v.erase(it);
		//cout<<p<<"rag"<<endl;
		if(visited[p]==0)
		dfs(p);
		if(v.size()==0)
		break;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v1;
		if(u!=v1)
		{
		s[u].push_back(v1);
		s[v1].push_back(u);
		}
	}
     dfs(1);
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100000],u,v,temp=0,a[300000];
vector<int>s[1000000];
void dfs(int x)
{
	cout<<x<<" ";
	//ram=min(a[x],ram);
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		int p=s[x][i];
		if(visited[p]==0)
		dfs(p);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v;
		if(u!=v)
		{
		s[u].push_back(v);
		s[v].push_back(u);
		}
	}
	for(i=0;i<=10000;i++)
	{

		sort(s[i].begin(), s[i].end());
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		{
			//ram=10000000009;
			dfs(i);
			//temp=temp+ram;
		}

	}
	//cout<<temp<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,y,i,b[26],ram,t,l=0,ans,z,j,visited[100005],u,v1,temp=0,a[300000];
vector<int>s[100005];
set<int>v;
//set<int>::iterator ptr;
void dfs(int x)
{
	cout<<x<<" ";
	visited[x]=1;
	for(int i=0;i<s[x].size();i++)
	{
		v.insert(s[x][i]);
	}

	while(1)
	{
		if(v.size()==0)
		break;
		auto it = v.begin();
		int p=*it;
		v.erase(it);
		//cout<<p<<"rag"<<endl;
		if(visited[p]==0)
		dfs(p);
		if(v.size()==0)
		break;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>x>>y;
	//for(i=1;i<=x;i++)
	//cin>>a[i];
	for(i=0;i<y;i++)
	{
		cin>>u>>v1;
		if(u!=v1)
		{
		s[u].push_back(v1);
		s[v1].push_back(u);
		}
	}
     dfs(1);
	//cout<<temp<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);

const int N = 1e5 + 2;
bool vis[N];
multiset<int> s[N];
queue<int> q;

void dfs(int node, int par){
	vis[node] = true;
	auto up1 = s[par].upper_bound(node);
	auto up2 = s[node].upper_bound(par);
	q.push(node);
	if (up1 != s[par].end() && up2 != s[node].end())if (*up1 < *up2 && !vis[*up1])dfs(*up1, par);
	for (auto x : s[node])if (!vis[x])dfs(x, node);
}

int main() {
	int n, m;
	cin >> n >> m;
	f(i, 0, m){
		int u, v;
		cin >> u >> v;
		s[u].insert(v);
		s[v].insert(u);
	}
	dfs(1, 1);
	while(!q.empty()){
		cout << q.front() << " ";
		q.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);

const int N = 1e5 + 2;
bool vis[N];
set<int> s[N];
queue<int> q;

void dfs(int node, int par){
	vis[node] = true;
	int up1 = *s[par].upper_bound(node);
	int up2 = *s[node].upper_bound(par);
	q.push(node);
	if (up1 < up2 && !vis[up1])dfs(up1, par);
	for (auto x : s[node])if (!vis[x])dfs(x, node);
}

int main() {
	int n, m;
	cin >> n >> m;
	f(i, 0, m){
		int u, v;
		cin >> u >> v;
		s[u].insert(v);
		s[v].insert(u);
	}
	dfs(1, 1);
	while(!q.empty()){
		cout << q.front() << " ";
		q.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);

const int N = 1e5 + 2;
int n, m;
bool vis[N];
multiset<int> s[N];
queue<int> q;

void dfs(int node){
	vis[node] = true;
	q.push(node);
	if (*s[node].begin() != node + 1 && !vis[node + 1] && node + 1 <= n)dfs(node + 1);
	for (auto x : s[node])if (!vis[x])dfs(x);
}

int main() {
	cin >> n >> m;
	f(i, 0, m){
		int u, v;
		cin >> u >> v;
		s[u].insert(v);
		s[v].insert(u);
	}
	dfs(1);
	while(!q.empty()){
		cout << q.front() << " ";
		q.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);

const int N = 1e5 + 2;
bool vis[N];
set<int> s[N];
queue<int> q;

void dfs(int node, int par){
	vis[node] = true;
	auto up1 = s[par].upper_bound(node);
	auto up2 = s[node].upper_bound(par);
	q.push(node);
	if (up1 != s[par].end() && up2 != s[node].end())if (*up1 < *up2 && !vis[*up1])dfs(*up1, par);
	for (auto x : s[node])if (!vis[x])dfs(x, node);
}

int main() {
	int n, m;
	cin >> n >> m;
	f(i, 0, m){
		int u, v;
		cin >> u >> v;
		s[u].insert(v);
		s[v].insert(u);
	}
	dfs(1, 1);
	while(!q.empty()){
		cout << q.front() << " ";
		q.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);

const int N = 1e5 + 2;
bool vis[N];
set<int> s[N];
queue<int> q;

void dfs(int node){
	vis[node] = true;
	q.push(node);
	for (auto x : s[node])if (!vis[x])dfs(x);
}
int main() {
	int n, m;
	cin >> n >> m;
	f(i, 0, m){
		int u, v;
		cin >> u >> v;
		s[u].insert(v);
		s[v].insert(u);
	}
	f(i, 1, n + 1)if (!vis[i])dfs(i);
	while(!q.empty()){
		cout << q.front() << " ";
		q.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);

const int N = 1e5 + 2;
int n, m;
bool vis[N];
set<int> s[N], ok;
queue<int> q;

void dfs(int node){
	vis[node] = true;
	q.push(node);
	ok.erase(node);
	for (auto x : s[node])if (!vis[x])ok.insert(x);
	int c = ok.size() ? *ok.begin() : 0;
	if (!c)return;
	if (!vis[c])dfs(c);
}

int main() {
	cin >> n >> m;
	f(i, 0, m){
		int u, v;
		cin >> u >> v;
		s[u].insert(v);
		s[v].insert(u);
	}
	ok.insert(1);
	dfs(1);
	while(!q.empty()){
		cout << q.front() << " ";
		q.pop();
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);

vector <int> adj[300005];
int visited[300005];
vector<int>v;
priority_queue<int,vector<int>,greater<int> >Q;
int node, edge;

int main()
{
    fast;
    cin >> node>>edge;
    int x,y;
    for(int i = 0; i < edge; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    visited[1]=1;
    Q.push(1);
    while(!Q.empty())
    {
        int x=Q.top();
        Q.pop();
        v.push_back(x);
        for(auto p:adj[x])
        {
            if(!visited[p])
            {
                Q.push(p);
                visited[p]=1;
            }
        }
    }
    for(auto p:v)
    {
        printf("%d ",p);
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 550000;

vector<int> adj[N];
set<int> s;
int vis[N];

int main() {
	ios::sync_with_stdio(0);
	int n, m; cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int cur = 1;
	vector<int> vec;
	while (true) {
		vec.push_back(cur);
		vis[cur] = 1;
		if (vec.size() == n) break;
		for (int v : adj[cur]) if (!vis[v]) s.insert(v);
		cur = *s.begin();
		s.erase(cur);
	}
	for (int x : vec) cout << x << " ";
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 550000
vector <int> adj[N];
int visited[N];
set<int>s;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int node,edge,x,y;
    cin >>node>>edge;
    for(int i = 0; i < edge; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    int cur=1;
    vector<int>v;
    while(true)
    {
        v.push_back(cur);
        visited[cur] = 1;
        if(v.size() == node)break;

        for(int y:adj[cur])
        {
            if(!visited[y])
            {
                s.insert(y);
            }
        }
        cur=*(s.begin());
        s.erase(cur);
    }
    for(int p:v)
    {
        cout<<p<<" ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);

vector <int> adj[100005];
int visited[100005];
int node, edge;

void dfs(int s)
{
    if(!visited[s])
    {
        visited[s] = 1;
        cout<<s<<" ";

        for(int i = 0; i < adj[s].size(); i++)
        {
            if(!visited[adj[s][i]])
                dfs(adj[s][i]);
        }
    }
}

int main()
{
    fast;
    cin >> node>>edge;
    int x,y;
    for(int i = 0; i < edge; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1);
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);

vector <int> adj[100005];
int visited[100005];
vector<int>v;
priority_queue<int,vector<int>,greater<int> >Q;
int node, edge;

int main()
{
    fast;
    cin >> node>>edge;
    int x,y;
    for(int i = 0; i < edge; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    visited[1]=1;
    Q.push(1);
    while(!Q.empty())
    {
        int x=Q.top();
        Q.pop();
        v.push_back(x);
        for(auto p:adj[x])
        {
            if(!visited[p])
            {
                Q.push(p);
                visited[p]=1;
            }
        }
    }
    for(auto p:v)
    {
        printf("%d ",p);
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);

vector <int> adj[550000];
int visited[550000];
set<int>s;
int node, edge;

int main()
{
    fast;
    cin >> node>>edge;
    int x,y;
    for(int i = 0; i < edge; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    int cur=1;
    vector<int>v;
    while(true)
    {
        v.push_back(cur);
        visited[cur] = 1;
        if(v.size() == node)break;

        for(int y:adj[cur])
        {
            if(!visited[y])
            {
                s.insert(y);
            }
        }
        cur=*(s.begin());
        s.erase(cur);
    }
    for(int p:v)
    {
        printf("%d ",p);
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<set<int>>g(n);
  for(int i = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    g[v].insert(u);
  }

  auto still = g;

  auto cmpPick = [&] (const int &u, const int &v) {
    int res_u = still[u].empty() ? INF : *still[u].begin();
    int res_v = still[v].empty() ? INF : *still[v].begin();
    return res_u < res_v;
  };

  multiset<int, decltype(cmpPick)>path(cmpPick);
  vector<int>sol;
  vector<bool>vis(n);
  auto EraseNode = [&] (int u) {
    for(auto v : g[u]) {
      auto z = still[v].find(u);
      if(z != end(still[v]))
        still[v].erase(z);
    }
    vis[u] = 1;
    path.insert(u);
    sol.push_back(u);
  };
  EraseNode(0);
  for(int i = 1; i < n; ++i) {
    int neighb_of = *path.begin();
    int mnV = *still[neighb_of].begin();
    path.erase(neighb_of);
    for(int u : g[mnV]) {
      if(!vis[u]) continue;
      auto z = still[u].find(mnV);
      if(z != end(still[u]))
        still[u].erase(z);
    }
    EraseNode(mnV);
    path.insert(neighb_of);
  }

  for(auto it : sol)
    cout << (it + 1 ) << ' ';

}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int main() {
#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<set<int>>g(n);
  for(int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    g[v].insert(u);
  }
  vector<bool>vis(n);
  vector<int>path;
  set<int>alive;
  auto EraseNode = [&] (int u) {
    vis[u] = true;
    path.push_back(u);
    for(auto v : g[u]) {
      if(!vis[v]) {
        alive.insert(v);
      }
    }
  };

  EraseNode(0);
  for(int i = 1; i < n; ++i) {
    int bag = *alive.begin();
    alive.erase(alive.begin());
    EraseNode(bag);
  }

  for(int u : path)
    cout << u + 1 << ' ';
  return 0;

}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int main() {
#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<set<int>>g(n);
  for(int i = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    g[v].insert(u);
  }

  auto still = g;

  auto cmpPick = [&] (const int &u, const int &v) {
    int res_u = still[u].empty() ? INF : *still[u].begin();
    int res_v = still[v].empty() ? INF : *still[v].begin();
    return res_u < res_v;
  };

  multiset<int, decltype(cmpPick)>path(cmpPick);
  vector<int>sol;
  vector<bool>vis(n);
  auto EraseNode = [&] (int u) {
    for(auto v : g[u]) {
      auto z = still[v].find(u);
      if(z != end(still[v]))
        still[v].erase(z);
    }
    vis[u] = 1;
    path.insert(u);
    sol.push_back(u);
  };
  EraseNode(0);
  for(int i = 1; i < n; ++i) {
    int neighb_of = *path.begin();
    int mnV = *still[neighb_of].begin();
    path.erase(neighb_of);
    for(int u : g[mnV]) {
      if(!vis[u]) continue;
      auto z = still[u].find(mnV);
      if(z != end(still[u]))
        still[u].erase(z);
    }
    EraseNode(mnV);
    path.insert(neighb_of);
  }

  for(auto it : sol)
    cout << (it + 1 ) << ' ';

}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int main() {
#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<set<int>>g(n);
  for(int i = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    g[v].insert(u);
  }

  auto still = g;
  auto cmpPick = [&] (const int &u, const int &v) {
    int res_u = still[u].empty() ? INF : *still[u].begin();
    int res_v = still[v].empty() ? INF : *still[v].begin();
    return res_u < res_v;
  };

  multiset<int, decltype(cmpPick)>path(cmpPick);
  vector<int>sol;
  vector<bool>vis(n);
  auto EraseNode = [&] (int u) {
    for(auto v : g[u]) {
      auto z = still[v].find(u);
      if(z != end(still[v]))
        still[v].erase(z);
    }
    vis[u] = 1;
    path.insert(u);
    sol.push_back(u);
  };
  return 0;
  EraseNode(0);
  for(int i = 1; i < n; ++i) {
    int neighb_of = *path.begin();
    int mnV = *still[neighb_of].begin();
    path.erase(neighb_of);
    for(int u : g[mnV]) {
      if(!vis[u]) continue;
      auto z = still[u].find(mnV);
      if(z != end(still[u]))
        still[u].erase(z);
    }
    EraseNode(mnV);
    path.insert(neighb_of);
  }

  for(auto it : sol)
    cout << (it + 1 ) << ' ';

}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int main() {
#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<set<int>>g(n);
  for(int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if(u==v)continue;
    g[u].insert(v);
    g[v].insert(u);
  }

  auto still = g;

  auto cmpPick = [&] (const int &u, const int &v) {
    int res_u = still[u].empty() ? INF : *still[u].begin();
    int res_v = still[v].empty() ? INF : *still[v].begin();
    return res_u < res_v;
  };

  multiset<int, decltype(cmpPick)>path(cmpPick);
  vector<int>sol;
  vector<bool>vis(n);
  auto EraseNode = [&] (int u) {
    for(auto v : g[u]) {
      auto z = still[v].find(u);
      if(z != end(still[v]))
        still[v].erase(z);
    }
    vis[u] = 1;
    path.insert(u);
    sol.push_back(u);
  };
  EraseNode(0);
  for(int i = 1; i < n; ++i) {
    int neighb_of = *path.begin();
    int mnV = *still[neighb_of].begin();
    path.erase(neighb_of);
    EraseNode(mnV);
    path.insert(neighb_of);
  }

  for(auto it : sol)
    cout << (it + 1 ) << ' ';

}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
int main() {
#ifndef ONLINE_JUDGE
  freopen("data.in", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<set<int>>g(n);
  for(int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    g[v].insert(u);
  }

  auto still = g;

  auto cmpPick = [&] (const int &u, const int &v) {
    int res_u = still[u].empty() ? INF : *still[u].begin();
    int res_v = still[v].empty() ? INF : *still[v].begin();
    return res_u < res_v;
  };

  multiset<int, decltype(cmpPick)>path(cmpPick);
  vector<int>sol;
  vector<bool>vis(n);
  auto EraseNode = [&] (int u) {
    for(auto v : g[u]) {
      auto z = still[v].find(u);
      if(z != end(still[v]))
        still[v].erase(z);
    }
    vis[u] = 1;
    path.insert(u);
    sol.push_back(u);
  };
  EraseNode(0);
  for(int i = 1; i < n; ++i) {
    int neighb_of = *path.begin();
    int mnV = *still[neighb_of].begin();
    path.erase(neighb_of);
    for(int u : g[mnV]) {
      if(!vis[u]) continue;
      auto z = still[u].find(mnV);
      if(z != end(still[u]))
        still[u].erase(z);
    }
    EraseNode(mnV);
    path.insert(neighb_of);
  }

  for(auto it : sol)
    cout << (it + 1 ) << ' ';

}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct park
{
    int u;
    int v;
    int canDelete = false;
};
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<park> v;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v.push_back({.u=a,.v=b});
    }
    vector<int> visited;
    int i = 1;
    visited.push_back(i);
    set<int> ss;
    ss.insert(1);
    priority_queue<int> p;
    while(int(visited.size()) < n)
    {
        for(int j = 0; j < int(v.size()); j++)
        {
            if(v[j].canDelete)
                continue;
            auto k = v[j];
            if(k.u == i)
            {
                if(ss.end() == ss.find(k.v))
                {
                    p.push(-k.v);
                    v[j].canDelete = true;
                    ss.insert(k.v);
                }
            }
            else if(k.v == i)
            {
                if(ss.end() == ss.find(k.u))
                {
                    p.push(-k.u);
                    v[j].canDelete = true;
                    ss.insert(k.u);
                }
            }
        }
        if(p.empty())
            break;
        i = -p.top();
        visited.push_back(i);
        p.pop();
    }
    for(auto& k : visited)
        cout << k << " ";
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
vector<int> park[100001];
char nodeAdded[100001];
int main()
{
//	freopen("test.txt", "r", stdin);
    memset(nodeAdded, 0, sizeof(char)*100001);
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        park[a].push_back(b);
        park[b].push_back(a);
    }
    int visited = 1;
    int i = 1;
    vector<int> ans;
    ans.push_back(1);
    nodeAdded[1] = 1;
    priority_queue<int,vector<int>,greater<int>> p;
    while(visited < n)
    {
        for(auto x : park[i])
        {
            if(nodeAdded[x] == 0)
            {
                p.push(x);
                nodeAdded[x] = 1;
            }
        }
        if(p.empty())
            break;
        i = p.top();
        p.pop();
        visited++;
        ans.push_back(i);
    }
    while(!p.empty())
    {
        ans.push_back(p.top());
        p.pop();
    }
    for(auto k : ans)
        fprintf(stdout, "%d ", k);
    fputc('\n', stdout);
    fflush(stdout);
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct Park
{
    int u;
    int v;
};
Park park[100001];
int parkSize = 0;
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        park[parkSize++] = {.u=a,.v=b};
    }
    vector<int> visited;
    int i = 1;
    visited.push_back(i);
    set<int> ss;
    ss.insert(1);
    priority_queue<int> p;
    while(int(visited.size()) < n)
    {
        int j = 0;
//        printf("park size=%d\n", parkSize);
        while(j < parkSize)
        {
            auto k = park[j];
            if(k.u == i)
            {
                if(ss.end() == ss.find(k.v))
                {
                    p.push(-k.v);
                    std::swap(park[j], park[parkSize-1]);
                    parkSize--;
                    ss.insert(k.v);
                    continue;
                }
            }
            else if(k.v == i)
            {
                if(ss.end() == ss.find(k.u))
                {
                    p.push(-k.u);
                    std::swap(park[j], park[parkSize-1]);
                    parkSize--;
                    ss.insert(k.u);
                    continue;
                }
            }
            j++;
        }
        if(p.empty())
            break;
        i = -p.top();
        visited.push_back(i);
        p.pop();
    }
    for(auto& k : visited)
        printf("%d ", k);
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct Park
{
    int u;
    int v;
};
Park park[100001];
int parkSize = 0;
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        park[parkSize++] = {.u=a,.v=b};
    }
//    vector<int> visited;
    int visited = 1;
    int i = 1;
    putchar('1');putchar(' ');
//    visited.push_back(i);
    set<int> ss;
    ss.insert(1);
    priority_queue<int> p;
    while(visited < n)
    {
        int j = 0;
        while(j < parkSize)
        {
            auto k = park[j];
            if(k.u == i)
            {
                if(ss.end() == ss.find(k.v))
                {
                    p.push(-k.v);
                    std::swap(park[j], park[parkSize-1]);
                    parkSize--;
                    ss.insert(k.v);
                    continue;
                }
            }
            else if(k.v == i)
            {
                if(ss.end() == ss.find(k.u))
                {
                    p.push(-k.u);
                    std::swap(park[j], park[parkSize-1]);
                    parkSize--;
                    ss.insert(k.u);
                    continue;
                }
            }
            j++;
        }
        if(p.empty())
            break;
        i = -p.top();
//        visited.push_back(i);
        visited++;
        printf("%d ", i);
        p.pop();
    }
    if(!p.empty())
    {
        printf("%d ", -p.top());
        p.pop();
    }
//    for(auto& k : visited)
//        printf("%d ", k);
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct park
{
    int u;
    int v;
    int canDelete = false;
};
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<park> v;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v.push_back({.u=a,.v=b});
    }
    //vector<int> visited;
    int visited = 1;
    int i = 1;
    printf("%d ", i);
    priority_queue<int> p;
    while(visited < n)
    {
        for(int j = 0; j < int(v.size()); j++)
        {
            if(v[j].canDelete)
                continue;
            auto k = v[j];
            if(k.u == i)
            {
                p.push(-k.v);
                v[j].canDelete = true;
            }
            else if(k.v == i)
            {
                p.push(-k.u);
                v[j].canDelete = true;
            }
        }
        if(p.empty())
            break;
        i = -p.top();
        printf("%d ", i);
        visited++;
        p.pop();
    }
//    for(auto& k : visited)
//        cout << k << " ";
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct Park
{
    int u;
    int v;
};
Park park[100001];
int parkSize = 0;
char nodeAdded[100001];
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    memset(nodeAdded, 0, sizeof(char)*100001);
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        park[parkSize++] = {.u=a,.v=b};
    }
    int visited = 1;
    int i = 1;
    putchar('1');putchar(' ');
    nodeAdded[1] = 1;
    priority_queue<int> p;
    while(visited < n)
    {
        int j = 0;
        while(j < parkSize)
        {
            auto k = park[j];
            if(k.u == i && nodeAdded[k.v] == 0)
            {
                p.push(-k.v);
                std::swap(park[j], park[parkSize-1]);
                parkSize--;
                nodeAdded[k.v] = 1;
                continue;
            }
            else if(k.v == i && nodeAdded[k.u] == 0)
            {
                p.push(-k.u);
                std::swap(park[j], park[parkSize-1]);
                parkSize--;
                nodeAdded[k.u] = 1;
                continue;
            }
            j++;
        }
        if(p.empty())
            break;
        i = -p.top();
        p.pop();
        visited++;
        printf("%d ", i);
    }
    while(!p.empty())
    {
        printf("%d ", -p.top());
        p.pop();
    }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define LOCAL   0
struct Park
{
    int u;
    int v;
};
Park park[100001];
int parkSize = 0;
char nodeAdded[100001];
using namespace std;
int main()
{
#if LOCAL
	auto start_time = clock();
#endif
//	freopen("test.txt", "r", stdin);
    memset(nodeAdded, 0, sizeof(char)*100001);
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        park[parkSize++] = {.u=a,.v=b};
    }
    int visited = 1;
    int i = 1;
    vector<int> ans;
    ans.push_back(1);
    nodeAdded[1] = 1;
    priority_queue<int> p;
    while(visited < n)
    {
        int j = 0;
        while(j < parkSize)
        {
            auto k = park[j];
            if(k.u == i && nodeAdded[k.v] == 0)
            {
                p.push(-k.v);
                std::swap(park[j], park[parkSize-1]);
                parkSize--;
                nodeAdded[k.v] = 1;
                continue;
            }
            else if(k.v == i && nodeAdded[k.u] == 0)
            {
                p.push(-k.u);
                std::swap(park[j], park[parkSize-1]);
                parkSize--;
                nodeAdded[k.u] = 1;
                continue;
            }
            j++;
        }
        if(p.empty())
            break;
        i = -p.top();
        p.pop();
        visited++;
        ans.push_back(i);
    }
    while(!p.empty())
    {
        ans.push_back(-p.top());
        p.pop();
    }
    for(i = 0; i < int(ans.size()); i++)
        fprintf(stdout, "%d ", ans[i]);
    fputc('\n', stdout);
    fflush(stdout);
#if LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct Park
{
    int u;
    int v;
};
Park park[100001];
int parkSize = 0;
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        park[parkSize++] = {.u=a,.v=b};
    }
//    vector<int> visited;
    int i = 1;
    putchar('1');putchar(' ');
//    visited.push_back(i);
    set<int> ss;
    ss.insert(1);
    priority_queue<int> p;
    while(int(ss.size()) < n)
    {
        int j = 0;
        while(j < parkSize)
        {
            auto k = park[j];
            if(k.u == i)
            {
                if(ss.end() == ss.find(k.v))
                {
                    p.push(-k.v);
                    std::swap(park[j], park[parkSize-1]);
                    parkSize--;
                    ss.insert(k.v);
                    continue;
                }
            }
            else if(k.v == i)
            {
                if(ss.end() == ss.find(k.u))
                {
                    p.push(-k.u);
                    std::swap(park[j], park[parkSize-1]);
                    parkSize--;
                    ss.insert(k.u);
                    continue;
                }
            }
            j++;
        }
        if(p.empty())
            break;
        i = -p.top();
//        visited.push_back(i);
        printf("%d ", i);
        p.pop();
    }
    if(!p.empty())
    {
        printf("%d ", -p.top());
        p.pop();
    }
//    for(auto& k : visited)
//        printf("%d ", k);
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
struct park
{
    int u;
    int v;
    int canDelete = false;
};
using namespace std;
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<park> v;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v.push_back({.u=a,.v=b});
    }
    vector<int> visited;
    int i = 1;
    visited.push_back(i);
    set<int> ss;
    ss.insert(1);
    priority_queue<int> p;
    while(int(visited.size()) < n)
    {
        for(int j = 0; j < int(v.size()); j++)
        {
            if(v[j].canDelete)
                continue;
            auto k = v[j];
            if(k.u == i)
            {
                if(ss.end() == ss.find(k.v))
                {
                    p.push(-k.v);
                    v[j].canDelete = true;
                    ss.insert(k.v);
                }
            }
            else if(k.v == i)
            {
                if(ss.end() == ss.find(k.u))
                {
                    p.push(-k.u);
                    v[j].canDelete = true;
                    ss.insert(k.u);
                }
            }
        }
        if(p.empty())
            break;
        i = -p.top();
        visited.push_back(i);
        p.pop();
    }
    for(auto& k : visited)
        cout << k << " ";
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define f2(n,m) for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define mem(a,b) memset(a,b,sizeof(a))
#define rf(m,a) for(ll i=m;i>=a;i--)
#define ftt ll t;cin>>t;while(t--)
#define f(a,m) for(ll i=a;i<m;i++)
#define  vll vector<ll>
#define nl cout<<'\n'
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first
#include <vector>
#define p 1000000007

int dfs(ll u,vector<ll>adj[],bool vis[],ll cnt, ll n,vector<ll>vt,bool used2[]) {
        if(vt.size()==0){return 0;}
        for (ll v :adj[u])
           {
               if (vis[v]==0&&used2[v]==0)
               {vt.pb(v);used2[v]=1;}}
           sort(vt.begin(),vt.end());
           ll k=vt[0];
           cout<<k<<" ";
           vis[k]=1;
           auto it=vt.begin();
            vt.erase(it);
            cnt++;
           dfs(k,adj,vis,cnt,n,vt,used2);

}

int main()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    vector<ll>adj[n+1];
    f(0,m){cin>>a>>b;adj[a].pb(b);adj[b].pb(a);}
    bool used2[100001];
    mem(used2,0);
    bool vis[n+1];
    mem(vis,0);
    used2[1]=1;
    vector<ll>vv;
    vv.pb(1);
    dfs(1,adj,vis,1,n,vv,used2);

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define f2(n,m) for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define mem(a,b) memset(a,b,sizeof(a))
#define rf(m,a) for(ll i=m;i>=a;i--)
#define ftt ll t;cin>>t;while(t--)
#define f(a,m) for(ll i=a;i<m;i++)
#define  vll vector<ll>
#define nl cout<<'\n'
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first
#include <vector>
#define p 1000000007

int dfs(ll u,vector<ll>adj[],bool vis[],ll cnt, ll n,vector<ll>vt) {
        if(cnt==n){return 0;}

        for (ll v :adj[u])
           {if (std::find(vt.begin(), vt.end(), v)== vt.end())
               {vt.pb(v);}}
           sort(vt.begin(),vt.end());
           for(ll i=0;i<vt.size();i++)
           {ll k=vt[i];
            if(vis[k]==0)
           {vis[k]=1;cnt++;
            cout<<k<<" ";
           dfs(k,adj,vis,cnt,n,vt);}}

}

int main()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    vector<ll>adj[n+1];
    f(0,m){cin>>a>>b;adj[a].pb(b);adj[b].pb(a);}
    bool vis[n+1];
    mem(vis,0);
    cout<<1<<" ";vis[1]=1;
    vector<ll>vv;
    dfs(1,adj,vis,1,n,vv);

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll int
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define f2(n,m) for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define mem(a,b) memset(a,b,sizeof(a))
#define rf(m,a) for(ll i=m;i>=a;i--)
#define ftt ll t;cin>>t;while(t--)
#define f(a,m) for(ll i=a;i<m;i++)
#define  vll vector<ll>
#define nl cout<<'\n'
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first
#include <vector>
#define p 1000000007

int dfs(ll u,vector<ll>adj[],bool vis[],ll cnt, ll n,vector<ll>vt,bool used2[]) {
        if(vt.size()==0){return 0;}
        for (ll v :adj[u])
           {
               if (vis[v]==0&&used2[v]==0)
               {vt.pb(v);used2[v]=1;}}
           sort(vt.begin(),vt.end());
           ll k=vt[0];
           cout<<k<<" ";
           vis[k]=1;
           auto it=vt.begin();
            vt.erase(it);
            cnt++;
           dfs(k,adj,vis,cnt,n,vt,used2);
           return 0;

}

int main()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    vector<ll>adj[n+1];
    f(0,m){cin>>a>>b;adj[a].pb(b);adj[b].pb(a);}
    bool used2[100001];
    mem(used2,0);
    bool vis[n+1];
    mem(vis,0);
    used2[1]=1;
    vector<ll>vv;
    vv.pb(1);
    dfs(1,adj,vis,1,n,vv,used2);

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define f2(n,m) for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)
#define mem(a,b) memset(a,b,sizeof(a))
#define rf(m,a) for(ll i=m;i>=a;i--)
#define ftt ll t;cin>>t;while(t--)
#define f(a,m) for(ll i=a;i<m;i++)
#define  vll vector<ll>
#define nl cout<<'\n'
#define pb push_back
#define sp <<" "<<
#define ss second
#define ff first
#define p 1000000007
set<ll>settt;

int dfs(ll u,vector<ll>adj[],bool vis[],ll cnt, ll n,vector<ll>vt) {
        if(cnt==n){return 0;}

        for (ll v :adj[u])
           {if(settt.find(v)==settt.end())
               {vt.pb(v);settt.insert(v);}}
           sort(vt.begin(),vt.end());
           for(ll i=0;i<vt.size();i++)
           {ll k=vt[i];
            if(vis[k]==0)
           {vis[k]=1;cnt++;
            cout<<k<<" ";
           dfs(k,adj,vis,cnt,n,vt);}}

}

int main()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    vector<ll>adj[n+1];
    f(0,m){cin>>a>>b;adj[a].pb(b);adj[b].pb(a);}
    bool vis[n+1];
    mem(vis,0);
    cout<<1<<" ";vis[1]=1;
    vector<ll>vv;
    dfs(1,adj,vis,1,n,vv);

    return 0;

}


import java.util.*;

public class HelloWorld{

     public static void main(String []args){
        Scanner sj = new Scanner(System.in);
        int n = sj.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        int x[] = new int[n+1];
        int y[] = new int[n+1];
        for(int i=0;i<n;i++){
            a[i] = sj.nextInt();
            x[a[i]] = i+1;
        }
        for(int i=0;i<n;i++){
            b[i] = sj.nextInt();
            y[b[i]] = i+1;
        }
        int count = 0;
        for(int i=1;i<n+1;i++){
            if(y[i]-x[i]<=0){
                count++;
            }
        }
        if(count==n){
            System.out.println(0);
        }else{
            System.out.println(count);
        }

     }
}


import java.util.*;

public class HelloWorld{

     public static void main(String []args){
        Scanner sj = new Scanner(System.in);
        int n = sj.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        int x[] = new int[n+1];

        for(int i=0;i<n;i++){
            a[i] = sj.nextInt();
        }
        for(int i=0;i<n;i++){
            b[i] = sj.nextInt();
        }
        int count = 0;
        for(int i=1;i<n+1;i++){
            x[i]=0;
        }
        int j = 0;
        for(int i=1;i<n+1;i++){
            if(x[a[j]]==0){
                if(a[j]!=b[i-1]){
                    x[b[i-1]] = 1;
                    count++;
                }else{
                    x[a[j]] = 1;
                    j++;
                }
            }

        }
        System.out.println(count);

     }
}


import java.util.*;

public class HelloWorld{

     public static void main(String []args){
        Scanner sj = new Scanner(System.in);
        int n = sj.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        int x[] = new int[n+1];

        for(int i=0;i<n;i++){
            a[i] = sj.nextInt();
        }
        for(int i=0;i<n;i++){
            b[i] = sj.nextInt();
        }
        int count = 0;
        for(int i=1;i<n+1;i++){
            x[i]=0;
        }
        int j = 0;
        for(int i=1;i<n+1;i++){
            if(x[a[j]]==0){
                if(a[j]!=b[i-1]){
                    x[b[i-1]] = 1;
                    count++;
                }else{
                    x[a[j]] = 1;
                    j++;
                }
            }

        }

     }
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int N;
vector<int> in, out, outinv;
int ret[100000 + 10];

int main() {
	cin >> N;
	in.resize(N), out.resize(N), outinv.resize(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> in[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> out[i];
	}

	reverse(in.begin(), in.end()), reverse(out.begin(), out.end());
	for (int i = 0; i < N; i++)outinv[out[i]] = i;
	int pointer = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (in[i] != out[pointer]) {
			ans++;
			ret[outinv[in[i]]]++;
		}
		else {
			do {
				pointer++;
			} while (ret[pointer] != 0);
		}

	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

void answer(){
    int n,m=0,ans=0,x=0;
    cin>>n;
    int a[n+1],h[n+5];
    std::vector<pair<int,int>> v;
    for(int i=0;i<n;i++){ cin>>a[i]; h[a[i]]=i+1; }
    for(int i=0;i<n;i++){
        cin>>x;
        if(h[x]>i+1) ans++;
        if(ans>0 && h[x]==i+1) ans++;
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q;
    //while(q--){
        answer();
    //}
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

void answer(){
    int n;
    cin>>n;
    map<int,int> m;
    int a;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        m[a]=i+1;
    }
    int b[n];
    for(int i=0;i<n;i++)
    cin>>b[i];
    int mi=m[b[n-1]],c=0;
    for(int i=n-2;i>=0;i--)
    {
        if(m[b[i]]>mi)
        c++;
        else
        mi=m[b[i]];
    }
    cout<<c<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q;
    //while(q--){
        answer();
    //}
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

void answer(){
    int n,m=0,ans=0,x=0;
    cin>>n;
    int a[n+1],h[n+5]={},b[n+1];
    std::vector<pair<int,int>> v;
    for(int i=0;i<n;i++){ cin>>a[i]; }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        if(h[a[i]]==1) continue;
        for(int j=m;j<n;j++){
            if(a[i]!=b[j] && h[b[j]]==0) ans++;
            h[b[j]]=1;
            m = j;
            if(a[i]==b[j]) break;
        }
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q;
    //while(q--){
        answer();
    //}
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

void answer(){
    int n,m=0,ans=0,x=0;
    cin>>n;
    int a[n+1],h[n+5];
    std::vector<pair<int,int>> v;
    for(int i=0;i<n;i++){ cin>>a[i]; h[a[i]]=i+1; }
    for(int i=0;i<n;i++){
        cin>>x;
        v.pb(mp(h[x],i+1));
    }
    for(int i=0;i<n;i++){
        m = max(m,v[i].S-v[i].F);
    }
    cout<<m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q;
    //while(q--){
        answer();
    //}
    return 0;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

void answer(){
    int n,m=0,ans=0,x=0;
    cin>>n;
    int a[n+1],h[n+5]={},b[n+1];
    std::vector<pair<int,int>> v;
    for(int i=0;i<n;i++){ cin>>a[i]; }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        if(h[a[i]]==1) continue;
        for(int j=i;j<n;j++){
            if(a[i]!=b[j] && h[b[j]]==0) ans++;
            h[b[j]]=1;
            if(a[i]==b[j]) break;
        }
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q;
    //while(q--){
        answer();
    //}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int before[n];
	int after[n];
	for(int i=0;i<n;i++){
		cin>>before[i];
	}

	for(int i=0;i<n;i++){
		cin>>after[i];
	}

	int visited[n+1]={0};
	int chalan[n+1]={0};
	int ans=0;
	int prev=-1;
	for(int i=0;i<n;i++){
			if(chalan[before[i]]){
				continue;
			}
		int now=before[i];
		visited[now]=1;
		int start=0;
		start=prev+1;
		while(after[start]!=now&&start<n){

			if(!visited[after[start]]&&!chalan[after[start]]){
				chalan[after[start]]++;
				ans++;
			}
			start++;
		}
		prev=++start;

	}
	cout<<ans;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int before[n];
	int after[n];
	for(int i=0;i<n;i++){
		cin>>before[i];
	}

	for(int i=0;i<n;i++){
		cin>>after[i];
	}

	int visited[n+1]={0};
	int chalan[n+1]={0};
	int ans=0;
	int prev=-1;
	for(int i=0;i<n;i++){
		/*	if(chalan[before[i]]){
				continue;
			}*/
		int now=before[i];
		visited[now]=1;
	//	int start=0;
		int start=prev+1;
		while(after[start]!=now&&start<n){

			if(!visited[after[start]]&&!chalan[after[start]]){
				chalan[after[start]]++;
				ans++;
			}
			start++;
		}
		prev=start;

	}
	cout<<ans;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int before[n];
	int after[n];
	for(int i=0;i<n;i++){
		cin>>before[i];
	}

	for(int i=0;i<n;i++){
		cin>>after[i];
	}

	int visited[n+1]={0};
	int chalan[n+1]={0};
	int ans=0;
	int prev=0;
	for(int i=0;i<n;i++){
			if(chalan[before[i]]){
				continue;
			}
		int now=before[i];
		visited[now]=1;
		int start=0;
		while(after[start]!=now){

			if(!visited[after[start]]&&!chalan[after[start]]){
				chalan[after[start]]++;
				ans++;
			}
			start++;
		}

	}
	cout<<ans;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int before[n];
	int after[n];
	for(int i=0;i<n;i++){
		cin>>before[i];
	}

	for(int i=0;i<n;i++){
		cin>>after[i];
	}

	int visited[n+1]={0};
	int chalan[n+1]={0};
	int ans=0;
	for(int i=0;i<n;i++){
		int now=before[i];
		visited[now]=1;
		int start=0;
		while(after[start]!=now){
			if(!visited[after[start]]&&!chalan[after[start]]){
				chalan[after[start]]++;
				ans++;
			}
			start++;
		}
	}
	cout<<ans;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int before[n];
	int after[n];
	for(int i=0;i<n;i++){
		cin>>before[i];
	}

	for(int i=0;i<n;i++){
		cin>>after[i];
	}

	int visited[n+1]={0};
	int chalan[n+1]={0};
	int ans=0;
	int prev=-1;
	for(int i=0;i<n;i++){
			if(chalan[before[i]]){
				continue;
			}
		int now=before[i];
		visited[now]=1;
	//	int start=0;
		int start=prev+1;
		while(after[start]!=now&&start<n){

			if(!visited[after[start]]&&!chalan[after[start]]){
				chalan[after[start]]++;
				ans++;
			}
			start++;
		}
		prev=start;

	}
	cout<<ans;
	return 0;

}


#include <bits/stdc++.h>
#define thicc(boi) boi.size()
#define magiczne ios_base::sync_with_stdio(0);
#define linijki cin.tie(NULL);

using namespace std;

int xd[200007];

int main()
{
    magiczne linijki;
    int n, res = 0, diff = 1;
    cin >> n;
    for (int i = n;i>0;i--)
    	cin >> xd[i];
    for (int i = 2*n;i>n;i--)
    	cin >> xd[i];
//    for (int i = 1;i<=2*n;i++)
//    	cout << xd[i] << ' ';
	int i = 1, j = n + 1;
	while (i <= n)
	{
		while (xd[i] != xd[j])
			i++;
		if (i == j)
			break;
		res += i - diff;
		diff = i + 1;
		i++;
		j++;
	}
	cout << res;
    return 0;
}


#include <bits/stdc++.h>
#define thicc(boi) boi.size()
#define magiczne ios_base::sync_with_stdio(0);
#define linijki cin.tie(NULL);

using namespace std;

int main()
{
	magiczne linijki
	int n, a, res = 0;
	vector <int> xd;
	vector <int> cf;
	cin >> n;
	for (int i = 0;i<n;i++)
	{
		cin >> a;
		xd.push_back(a);
	}
	for (int i = 0;i<n;i++)
	{
		cin >> a;
		cf.push_back(a);
	}
	while (thicc(cf))
	{
		if (xd.front() == cf.front())
		{
			xd.erase(xd.begin());
			cf.erase(cf.begin());
		}
		else
		{
			res++;
			a = cf.front();
			cf.erase(cf.begin());
			for (int i = 0;i<thicc(xd);i++)
				if (xd[i] == a)
				{
					xd.erase(xd.begin() + i);
					break;
				}
		}
	}
	cout << '\n' << res;
	return 0;
}


#include <bits/stdc++.h>
#define thicc(boi) boi.size()
#define magiczne ios_base::sync_with_stdio(0);
#define linijki cin.tie(NULL);

using namespace std;

int main()
{
	magiczne linijki
	int n, a, res = 0;
	set <int> staszic;
	vector <int> xd;
	vector <int> cf;
	cin >> n;
	for (int i = 0;i<n;i++)
	{
		cin >> a;
		xd.push_back(a);
	}
	for (int i = 0;i<n;i++)
	{
		cin >> a;
		cf.push_back(a);
	}
	while (thicc(cf))
	{
		if (xd.front() == cf.front())
		{
			xd.erase(xd.begin());
			cf.erase(cf.begin());
		}
		else
		{
			if (staszic.count(xd.front()))
			{
				xd.erase(xd.begin());
				continue;
			}
			res++;
			a = cf.front();
			cf.erase(cf.begin());
			staszic.insert(a);
		}
	}
	cout << '\n' << res;
	return 0;
}


#include <bits/stdc++.h>
#define thicc(boi) boi.size()
#define magiczne ios_base::sync_with_stdio(0);
#define linijki cin.tie(NULL);

using namespace std;

int xd[200007];

int main()
{
    magiczne linijki;
    int n, res = 0, diff = 1;
    cin >> n;
    for (int i = n;i>0;i--)
    	cin >> xd[i];
    for (int i = 2*n;i>n;i--)
    	cin >> xd[i];
//    for (int i = 1;i<=2*n;i++)
//    	cout << xd[i] << ' ';
	int i = 1, j = n + 1;
	while (i < n)
	{
		while (xd[i] != xd[j])
			i++;
		res += i - diff;
		diff += i;
		i++;
		j++;
	}
	cout << res;
    return 0;
}