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