#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  unordered_map<int, int> map;
  vector<pair<int, int>> A(M);
  if (N == 1 && M == 0) {
    cout << 0 << endl;
    goto end2;
  }
  if (N == 1) {
    for (int i = 0; i < M; i++) {
      cin >> A[i].first >> A[i].second;
      if (!map.count(A[i].first))
        map[A[i].first] = A[i].second;
      else if (map[A[i].first] != A[i].second) {
        cout << -1 << endl;
        goto end1;
      }
      if (A[i].second == 0 && i == M - 1) {
        cout << 0 << endl;
        break;
      }
    }
  } else {
    for (int i = 0; i < M; i++) {
      cin >> A[i].first >> A[i].second;
      if (!map.count(A[i].first))
        map[A[i].first] = A[i].second;
      else if (map[A[i].first] != A[i].second) {
        cout << -1 << endl;
        goto end1;
      } else {
        A[i].second = 0;
        A[i].first = 2;
      }
      if (A[i].first == 1 && A[i].second == 0) {
        cout << -1 << endl;
        goto end;
      }
    }
    if (!map.count(1)) ans += pow(10, N - 1);
    for (int i = 0; i < M; i++) {
      ans += pow(10, N - A[i].first) * A[i].second;
    }
    cout << ans << endl;
  }
end1:
  N = N;
end2:
  N = N;
end:
  N = N;
}
