// darksta5's template v2.0

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

class DisjointSet
{
private:
  int _sz, _numSets;
  vector<int> _par, _setSz, _rank;

public:
  DisjointSet(int sz)
  {
    _sz = sz;
    _numSets = sz;
    _setSz.assign(sz, 1);
    _rank.assign(sz, 0);
    _par.assign(sz, 0);
    for (int i = 0; i < sz; i++)
    {
      _par[i] = i;
    }
  }

  int sz()
  {
    return _sz;
  }

  int numSets()
  {
    return _numSets;
  }

  int setSz(int i)
  {
    return _setSz[find(i)];
  }

  int find(int i)
  {
    int x = i;
    while (x != _par[x])
    {
      x = _par[x];
    }

    return _par[i] = x;
  }

  bool isSame(int i, int j)
  {
    return find(i) == find(j);
  }

  void uni(int i, int j)
  {
    if (!isSame(i, j))
    {
      _numSets--;
      int x = find(i);
      int y = find(j);
      if (_rank[x] < _rank[y])
      {
        _par[x] = y;
        _setSz[y] += _setSz[x];
      }
      else
      {
        _par[y] = x;
        _setSz[x] += _setSz[y];
        if (_rank[x] == _rank[y])
        {
          _rank[x]++;
        }
      }
    }
  }
};

ll make_key(int x, int y)
{
  return (ll)x * 200050LL + (ll)y;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, r1, r2;
  cin >> n >> r1 >> r2;
  DisjointSet ds1(n), ds2(n);

  for (int i = 0; i < r1; i++)
  {
    int x, y;
    cin >> x >> y;
    ds1.uni(x - 1, y - 1);
  }

  for (int i = 0; i < r2; i++)
  {
    int x, y;
    cin >> x >> y;
    ds2.uni(x - 1, y - 1);
  }

  unordered_map<ll, int> cnt;
  for (int i = 0; i < n; i++)
  {
    ll key = make_key(ds1.find(i), ds2.find(i));
    cnt[key]++;
  }

  for (int i = 0; i < n; i++)
  {
    ll key = make_key(ds1.find(i), ds2.find(i));
    if (i < n - 1)
    {
      cout << cnt[key] << " ";
    }
    else
    {
      cout << cnt[key] << endl;
    }
  }
}
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

/*int main(){
  int n, m;
  cin >> n >> m;
  vi vec(n);
  vi num(n);
  rep(i,m){
    int si, ci;
    cin >> si >> ci;
    si -= 1;
    if (vec.at(si) != ci) num.at(si)++;
    vec.at(si) = ci;
  }
  if (num.at(0) != 1 ){
    cout << -1 << endl;
    return 0;
  }
  REP(i,1,n){
    if (num.at(i) > 1){
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i,n){
    cout << vec.at(i);
  }
  cout << endl;
  return 0;
}*/

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  rep(i,m) cin >> p.at(i).first >> p.at(i).second;
  rep(i,1000){
    vi d(1, i%10);
    int nx = i / 10;
    while (nx){
      d.push_back(nx%10);
      nx /= 10;
    }
    if ((int)d.size() != n) continue;
    reverse(d.begin(), d.end());
    bool ok = true;
    rep(i,m){
      if (d[p.at(i).first-1] != p.at(i).second) ok = false;
    }
    if (ok){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
