#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(10) << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI ans(n, -1);
  bool flag = true;
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    s--;
    if(ans[s] != -1 && ans[s] != c) flag = false;
    ans[s] = c;
  }
  if (ans[0] == -1 && n != 1) ans[0] = 1;
  if(ans[0] == -1 && n == 1) ans[0] = 0;
  if(flag && ans[0] != 0) {
    rep(i, n) {
      if(ans[i] != -1) cout << ans[i];
      else cout << 0;
    }
    cout << endl;
  }
  else out(-1);

  return 0;
}
