#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];
    }
  }
  for (int i = 0; i < N; i++) b *= 10;
  if (a >= b && a < b * 10)
    cout << a;
  else
    cout << -1;
Exit:;
}
