#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
bool isp(ll n) {
  bool res = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res = false;
      break;
    }
  }
  return res;
}
ll ctoi(char c) {
  if (c == '0')
    return 0;
  else if (c == '1')
    return 1;
  else if (c == '2')
    return 2;
  else if (c == '3')
    return 3;
  else if (c == '4')
    return 4;
  else if (c == '5')
    return 5;
  else if (c == '6')
    return 6;
  else if (c == '7')
    return 7;
  else if (c == '8')
    return 8;
  else if (c == '9')
    return 9;
  else
    return -1;
}
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> keta(M);
  ll cnt = 1;
  vector<char> num(M);
  for (ll i = 0; i < M; i++) cin >> keta[i] >> num[i];
  bool ok = true;
  for (ll i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (keta[i] == keta[j] && num[i] != num[j]) ok = false;
    }
  }
  ll ans = 0;
  if (N != 1) {
    for (ll i = 0; i < M; i++) {
      if (num[i] == '0' && keta[i] == 1) ok = false;
    }
  }
  if (ok) {
    for (ll i = 0; i < N; i++) cnt *= 10;
    for (int i = cnt / 10; i < cnt; i++) {
      bool c = true;
      string s = to_string(i);
      for (ll j = 0; j < M; j++) {
        if (s[keta[j] - 1] != num[j]) {
          c = false;
          break;
        }
      }
      if (c) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  if (!(ok)) cout << "-1" << endl;
}
