#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1e9;
int main() {
  int N, M;
  cin >> N >> M;
  int a[3] = {INF, INF, INF};
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == INF)
      a[s] = c;
    else if (a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (i == 0 && a[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (a[i] == INF) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else
      cout << a[i];
  }
  cout << endl;
  return 0;
}
