#include <bits/stdc++.h>
using namespace std;
int mypow(int x, int y) {
  int powe = 1;
  for (int i = 0; i < (int)(y); i++) {
    powe *= x;
  }
  return powe;
}
int main() {
  int N, M;
  int c;
  int s;
  int num[3] = {-1, -1, -1};
  int flag = 1;
  cin >> N >> M;
  for (int i = 0; i < (int)(M); i++) {
    cin >> s >> c;
    if (num[s - 1] == -1)
      num[s - 1] = c;
    else if (num[s - 1] != c)
      flag = 0;
  }
  if (num[0] == 0) flag = 0;
  int sum = 0;
  for (int i = 0; i < (int)(N); i++) {
    if (num[0] == -1)
      num[0] = 1;
    else if (num[i] == -1)
      num[i] = 0;
    sum += mypow(10, N - i - 1) * num[i];
  }
  if (flag)
    cout << sum << endl;
  else
    cout << -1 << endl;
  return 0;
}
