#include <bits/stdc++.h>
using namespace std;
const long long INFL = 1LL << 60;
const long long MOD = 1000000007;
const int INF = 1000000005;
const int MAX = 300000;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<char> v(N, -1);
  for (int i = 0; i < M; i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (s == 0 && v[s] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (v[s] != -1 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  string zero = "";
  string ans = "";
  for (int i = 0; i < N; i++) {
    zero += "0";
    ans += "0";
  }
  for (int i = 0; i < N; i++) {
    if (v[i] != -1) {
      ans[i] = v[i];
    }
  }
  if (ans == zero) {
    if (v[0] != -1) {
      cout << -1 << endl;
      return 0;
    } else {
      ans[0] = '1';
    }
  }
  cout << ans << endl;
}
