#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n, m;
  cin >> n >> m;
  vector <set <int>> sc (n);

  rep (i, m)
  {
    int s, c;
    cin >> s >> c;
    -- s;

    sc[s].insert (c);
  }
  vector <int> ans (n, 0);
  bool success = true;

  rep (i, sc.size ())
  {
    auto && elem = sc[i];
    if (elem.empty ())
    {
      if (i == 0 && n > 1) ans[i] = 1;
      else ans[i] = 0;
    }
    else if (elem.size () == 1)
    {
      auto c = * begin (elem);
      if (i == 0 && c == 0)
      {
        success = false;
        break;
      }
      ans[i] = c;
    }
    else
    {
      success = false;
      break;
    }
  }
  if (success)
  {
    for (auto && elem : ans) cout << elem;
    cout << endl;
  }
  else cout << -1 << endl;
}
