#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
int main() {
  int N, M;
  cin >> N >> M;
  vl info(3, -1);
  bool check = 0;
  for (ll i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (info[s] == -1 or info[s] == c)
      info[s] = c;
    else
      check = 1;
  }
  if (check)
    cout << -1 << endl;
  else if (N != 1 and info[0] == 0)
    cout << -1 << endl;
  else {
    for (ll i = 0; i < N; i++) {
      if (!i and info[i] == -1)
        cout << 1;
      else if (info[i] == -1)
        cout << 0;
      else
        cout << info[i];
    }
    cout << endl;
  }
  return 0;
}
