#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, i, j, S1, S2, S3;
  bool clear;
  cin >> N >> M;
  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  } else {
    vector<int> s(M + 1);
    vector<int> c(M + 1);
    clear = true;
    for (i = 1; i <= M; i++) cin >> s.at(i) >> c.at(i);
    for (i = 1; i <= M; i++) {
      if (s.at(i) > N || (N > 1 && s.at(i) == 1 && c.at(i) == 0)) {
        cout << -1 << endl;
        clear = false;
        break;
      }
    }
    if (clear == true) {
      for (i = 1; i <= M - 1; i++) {
        for (j = i + 1; j <= M; j++) {
          if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
            cout << -1 << endl;
            clear = false;
            break;
          }
        }
        if (clear == false) break;
      }
    }
    if (clear == true) {
      if (N == 1)
        cout << c.at(1) << endl;
      else if (N == 2) {
        S1 = 1;
        S2 = 0;
        for (i = 1; i <= M; i++) {
          if (s.at(i) == 1) S1 = c.at(i);
          if (s.at(i) == 2) S2 = c.at(i);
        }
        cout << S1 << S2 << endl;
      } else if (N == 3) {
        S1 = 1;
        S2 = 0;
        S3 = 0;
        for (i = 1; i <= M; i++) {
          if (s.at(i) == 1)
            S1 = c.at(i);
          else if (s.at(i) == 2)
            S2 = c.at(i);
          else if (s.at(i) == 3)
            S3 = c.at(i);
        }
        cout << S1 << S2 << S3 << endl;
      }
    }
  }
}
