#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, c = 1;
  cin >> N >> M;
  vector<int> V(N, 0);
  int arr[5][2];
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> arr[i][j];
    }
  }
  if (M < N - 1) {
    c = 0;
    cout << -1;
  } else {
    for (int i = 0; i < M; i++) {
      if (V[arr[i][0] - 1] == 0 || V[arr[i][0] - 1] == arr[i][1]) {
        V[arr[i][0] - 1] = arr[i][1];
      } else {
        c = 0;
        cout << -1;
        break;
      }
    }
  }
  if (c != 0) {
    for (auto x : V) {
      cout << x;
    }
  }
}
