#include <bits/stdc++.h>
using namespace std;
uint64_t MOD = 1000000007;
int CalcAns(vector<int> V) {
  int x = 0;
  for (int i = 0; i < V.size(); i++) {
    x *= 10;
    if (V.at(i) != -1) x += V.at(i);
  }
  return x;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> SC(M);
  for (int m = 0; m < M; m++) {
    int s, c;
    cin >> s >> c;
    SC.at(m) = make_pair(s, c);
  }
  bool mis = false;
  vector<int> V(N, -1);
  for (auto sc : SC) {
    int keta = sc.first - 1, num = sc.second;
    if (V.at(keta) != -1 && V.at(keta) != num)
      mis = true;
    else
      V.at(keta) = num;
  }
  int ans = -1;
  if (!mis) {
    if (V.size() == 1 || (V.size() != 1 && V.at(0) != 0)) ans = CalcAns(V);
  }
  cout << ans << endl;
}
