#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M], num[N];
  for (int i = 0; i < N; i++) num[i] = -1;
  bool ans = true;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (num[i] == -1)
      num[s[i] - 1] = c[i];
    else {
      if (num[s[i] - 1] != c[i]) {
        ans = false;
        break;
      }
    }
  }
  if (ans) {
    if (num[0] == 0 && N > 1) {
      cout << "-1" << endl;
      return 0;
    }
    for (int i = 0; i < N; i++) {
      if (num[i] == -1 && i != 0)
        cout << 0;
      else if (num[i] == -1 && i == 0)
        cout << 1;
      else
        cout << num[i];
    }
  } else
    cout << "-1" << endl;
  return 0;
}
