#include <bits/stdc++.h>
using namespace std;
void arr_int(int* given_arr, int n) {
  for (int i = 0; i < n; i++) scanf("%d", &given_arr[i]);
  return;
}
void solve();
int main(int argc, char const* argv[]) {
  solve();
  return 0;
}
void solve() {
  int N;
  scanf("%d\n", &N);
  int arr[N];
  memset(arr, 0, sizeof arr);
  int M;
  cin >> M;
  int set<int>;
  int ci;
  bool cannotbe = false;
  for (int i = 0; i < M; i++) {
    cin >> set<int>;
    cin >> ci;
    set<int> --;
    if ((arr[set<int>] != -1 && ci != arr[set<int>]))
      cannotbe = true;
    else {
      arr[set<int>] = ci;
    }
  }
  if (cannotbe || ((arr[0] == 0) && N != 1)) {
    cout << -1 << endl;
    return;
  }
  for (int i = 0; i < N; i++) cout << arr[i];
}
