#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int a = 0;
  int b = 1;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    int n = 1;
    cin >> s[i] >> c[i];
    for (int k = 0; k < N - s[i]; k++) n *= 10;
    a += n * c[i];
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1;
        goto Exit;
      } else if (s[i] == s[j]) {
        a -= n * c[i];
        break;
      }
    }
  }
  for (int i = 0; i < N - 1; i++) b *= 10;
  if (M == 0) {
    cout << b;
    goto Exit;
  } else {
    if (b == 1) {
      if (a >= 0 && a < 10)
        cout << a;
      else
        cout << -1;
    } else if (a >= b && a < b * 10)
      cout << a;
    else
      cout << -1;
  }
Exit:;
}
