#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll z = 0;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M), map(N + 1, 0);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = 0;
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        ans = -1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0 && N != 0) {
      ans = -1;
    }
  }
  if (ans == -1)
    cout << ans << endl;
  else {
    for (int i = 0; i < M; i++) {
      map[s[i]] = c[i];
    }
    for (int i = N; i >= 1; i--) {
      ans += map[i] * pow(10, N - i);
    }
    cout << ans << endl;
  }
}
