#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void add(T& a, T b) {
  a = ((a + b) % MOD + MOD) % MOD;
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  map<int, int> mp;
  for (int i = 0; i < N; i++) mp[i] = -1;
  bool ok = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (mp[s] == -1) {
      mp[s] = c;
    } else if (mp[s] != c) {
      ok = false;
    }
  }
  if (!ok)
    cout << -1 << endl;
  else {
    if (N == 1)
      cout << mp[0] << endl;
    else {
      if (mp[0] == 0)
        cout << -1 << endl;
      else {
        for (int i = 0; i < N; i++) {
          if (mp[i] != -1)
            cout << mp[i];
          else {
            if (i == 0)
              cout << 1;
            else
              cout << 0;
          }
        }
        cout << endl;
      }
    }
  }
}
