#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a[N];
  bool c[N];
  bool isOK = true;
  for (int i = 0; i < N; i++) {
    a[i] = 0;
    c[i] = false;
  }
  for (int i = 0; i < M; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    if (c[tmp1 - 1] == false) {
      a[tmp1 - 1] = tmp2;
      c[tmp1 - 1] = true;
    } else {
      if (a[tmp1 - 1] != tmp2) {
        isOK = false;
        break;
      }
    }
  }
  if (a[0] == 0) isOK = false;
  if (isOK) {
    int ans = 0;
    int tmp = 1;
    for (int i = N - 1; i > -1; i--) {
      ans += a[i] * tmp;
      tmp *= 10;
    }
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
