#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int ans[3] = {-1, -1, -1};
  bool have_answer = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] == -1) {
      ans[s] = c;
    } else if (ans[s] == c) {
      continue;
    } else {
      have_answer = false;
    }
  }
  if (ans[0] == -1) ans[0] = 1;
  for (int i = 0; i < 3; i++) {
    if (ans[i] == -1) ans[i] = 0;
  }
  if (!have_answer) {
    cout << "-1" << endl;
  } else {
    if (N == 1)
      cout << ans[0] << endl;
    else if (N == 2)
      cout << ans[0] * 10 + ans[1] << endl;
    else
      cout << ans[0] * 100 + ans[1] * 10 + ans[2] << endl;
  }
  return 0;
}
