#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int arr[4];
  memset(arr, -1, sizeof(arr));
  int FLAG = 0;
  while (M--) {
    int x, y;
    cin >> x >> y;
    if (arr[x] == -1) {
      arr[x] = y;
    } else if (arr[x] != -1) {
      if (arr[x] != y) {
        FLAG = 1;
      }
    }
  }
  if (FLAG == 1)
    cout << -1;
  else {
    if (arr[1] == -1 && N == 1) {
      cout << 0;
      return 0;
    } else if (arr[1] == -1 && N > 1) {
      cout << 1;
    } else if (arr[1] != -1) {
      if (arr[1] == 0) {
        cout << -1;
        return 0;
      } else
        cout << arr[1];
    }
    if (N != 1) {
      for (int i = 2; i <= N; i++) {
        if (arr[i] != -1) {
          cout << arr[i];
        } else {
          cout << 0;
        }
      }
    }
  }
}
