#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (int i = 0; i < n; i++) {
    ans[i] = -1;
  }
  bool ex = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] == -1) {
      ans[s - 1] = c;
    } else {
      if (ans[s - 1] != c) {
        ex = false;
      }
    }
    if (s == 1 && c == 0) {
      ex = false;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) ans[i] = 0;
  }
  if (ex) {
    int k = 0;
    int a = 1;
    for (int i = n - 1; i >= 0; i--) {
      k += a * ans[i];
      a *= 10;
    }
    cout << k;
  } else {
    cout << -1;
  }
}
