#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (M); ++i) cin >> s[i] >> c[i];
  vector<int> r(N);
  int a = 0;
  for (int i = 0; i < (N); ++i) r[i] = 10;
  for (int i = 0; i < (M); ++i) {
    if (r[s[i] - 1] == 10)
      r[s[i] - 1] = c[i];
    else if (r[s[i] - 1] != c[i])
      a++;
  }
  if (a != 0 || (N != 1 && r[0] == 0))
    cout << -1;
  else {
    if (r[0] == 10)
      cout << 1;
    else
      cout << r[0];
    for (int i = 1; i < N; i++) {
      if (r[i] == 10)
        cout << 0;
      else
        cout << r[i];
    }
  }
}
