#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int arr[100];
  int ifarr[100];
  for (int i = 0; i < 100; ifarr[i++] = 0)
    ;
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    if (arr[a] != b) {
      arr[a] = b;
      ifarr[a]++;
    }
  }
  if (N == 1) {
    if (M == 0)
      cout << "0";
    else
      cout << arr[1];
  } else {
    int i;
    for (i = 1; i <= N; i++) {
      if (ifarr[i] > 1) {
        cout << "-1";
        break;
      }
    }
    if (i == N + 1) {
      for (int i = 1; i <= N; i++) {
        if (i == 1) {
          if (ifarr[i] == 0 || arr[i] == 0)
            cout << "1";
          else
            cout << arr[i];
        } else {
          if (ifarr[i] == 0)
            cout << "0";
          else
            cout << arr[i];
        }
      }
    }
  }
  return 0;
}
