#include <bits/stdc++.h>
using namespace std;
const long long int LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N, -1);
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A[s] >= 0 && A[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    A[s] = c;
  }
  bool b = false;
  for (int i = 0; i < (N); ++i) {
    if (A[i] <= 0) {
      if (!b) {
        cout << -1 << endl;
        return 0;
      } else {
        cout << 0;
      }
    } else {
      b = true;
      cout << A[i];
    }
  }
  cout << endl;
  return 0;
}
