#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<int> v(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] != -1 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  if (v[0] != -1 && v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  string ans = "";
  for (int i = 0; i < N; i++) {
    if (v[i] != -1) {
      ans += to_string(v[i]);
    } else {
      ans += "0";
    }
  }
  cout << ans << endl;
}
