#include <bits/stdc++.h>
const int INF = 1001001001;
using namespace std;
int main() {
  int N, M;
  int a[3] = {10, 10, 10};
  int res = 0;
  cin >> N >> M;
  bool flag = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] == 10)
      a[s - 1] = c;
    else if (a[s - 1] != c)
      flag = false;
  }
  if (N == 1 && a[0] == 0) flag = false;
  if (flag) {
    for (int i = 0; i < N; i++) {
      if (a[i] == 10 && i == 0 && N > 1)
        cout << 1;
      else if (a[i] == 10)
        cout << 0;
      else
        cout << a[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
