#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, flag = 0;
  cin >> N >> M;
  vector<int> ans(N, 0);
  vector<int> count(N, 0);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1 && y == 0) {
      flag = 1;
      break;
    } else if (count.at(x - 1) == 0) {
      ans.at(x - 1) = y;
      count.at(x - 1)++;
    } else if (count.at(x - 1) != 0 && ans.at(x - 1) == y) {
      continue;
    } else if (count.at(x - 1) != 0 && ans.at(x - 1) != y) {
      flag = 1;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans.at(i) == 0) {
      ans.erase(ans.begin() + i);
    } else {
      break;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < ans.size(); i++) {
      cout << ans.at(i);
      if (i == ans.size()) {
        cout << endl;
      }
    }
  }
}
