#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[M + 1], c[M + 1];
  for (int i = 1; i <= (int)(M); i++) {
    cin >> s[i] >> c[i];
  }
  bool can = true;
  int check[4] = {-1, -1, -1, -1};
  for (int i = 1; i <= (int)(M); i++) {
    if (N != 1 && s[i] == 1 && c[i] == 0) {
      can = false;
      break;
    }
    if (check[s[i]] != -1 && check[s[i]] != c[i]) {
      can = false;
      break;
    }
    check[s[i]] = c[i];
  }
  if (N > 1 && (M == 0 || check[1] == -1)) {
    can = false;
  }
  int ans = 0;
  if (can) {
    for (int i = 1; i <= (int)(N); i++) {
      if (check[i] == -1) {
        continue;
      }
      ans += check[i] * pow(10, N - i);
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
}
