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