#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int U = 2e5 + 5;
const ll MOD = 1000000007;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(4, 0);
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (a[N - s + 1] == 0) {
      a[N - s + 1] = c;
    } else if (a[N - s + 1] != c) {
      cout << -1 << endl;
      ;
      return 0;
    }
  }
  int ans = a[1] + a[2] * 10 + a[3] * 100;
  if (ans < pow(10, N - 1) && N > 1) {
    cout << -1 << endl;
    ;
  } else
    cout << ans << endl;
  ;
  return 0;
}
