#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> C(N, 0);
  vector<int> flag(N, 0);
  vector<int> flag2(N, 0);
  for (int i = 0; i < (M); i++) {
    int x;
    cin >> x;
    cin >> C[x - 1];
    if (flag[x - 1] == 1) {
      if (C[x - 1] != flag2[x - 1]) {
        cout << -1 << endl;
        return 0;
      }
    }
    flag2[x - 1] = C[x - 1];
    flag[x - 1] = 1;
  }
  if (N != 1) {
    if (C[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (N); i++) cout << C[i];
  cout << endl;
  return 0;
}
