#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c;
  cin >> N >> M;
  vector<int> ans(N, -1);
  for (int i = 0; i < (M); ++i) {
    cin >> s >> c;
    if (ans.at(s - 1) == -1)
      ans.at(s - 1) = c;
    else if (ans.at(s - 1) == c)
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 1)
    cout << ans.at(0) << endl;
  else if (ans.at(0) == 0)
    cout << -1 << endl;
  else if (ans.at(0) == -1) {
    int ret = 0, a = 1;
    for (int i = 0; i < (N - 1); ++i) a *= 10;
    ret += a;
    for (int i = 1; i < N; i++) {
      int a = ans.at(i);
      if (a == -1) a = 0;
      for (int _ = 0; _ < (N - i - 1); ++_) a *= 10;
      ret += a;
    }
    cout << ret << endl;
  } else {
    int ret = 0;
    for (int i = 0; i < (N); ++i) {
      int a = ans.at(i);
      if (a == -1) a = 0;
      for (int _ = 0; _ < (N - i - 1); ++_) a *= 10;
      ret += a;
    }
    cout << ret << endl;
  }
}
