#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> mp;
  for (int i = 0; i < (M); i++) {
    int S, C;
    cin >> S >> C;
    if (N != 1 && S == 1 && C == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (mp.count(S)) {
      if (mp[S] != C) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      mp[S] = C;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (i == 1)
      cout << 1;
    else
      cout << mp[i];
  }
  cout << endl;
  return 0;
}
