#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<long long>>;
struct edge {
  long long from, to, cost;
};
signed main() {
  long long a, b;
  cin >> a >> b;
  vector<long long> c(b), d(b);
  for (long long i = 0; i < b; i++) cin >> c[i] >> d[i];
  if (a == 1) {
    long long k = -1;
    long long g = 0;
    bool t = 1;
    for (long long i = 0; i < b; i++) {
      if (k != -1 && d[i] != k) {
        t = 0;
      } else {
        k = d[i];
      }
    }
    if (!t) {
      cout << -1;
    } else
      cout << k;
  } else {
    bool ans = 0;
    vector<long long> e(a);
    for (long long i = 0; i < a; i++) e[i] = -1;
    for (long long i = 0; i < b; i++) {
      if (c[i] == 1 && d[i] == 0)
        ans = 1;
      else if (e[c[i] - 1] != -1 && e[c[i] - 1] != d[i])
        ans = 1;
      else
        e[c[i] - 1] = d[i];
    }
    if (ans)
      cout << -1;
    else {
      for (long long i = 0; i < a; i++) {
        if (i == 0) {
          if (e[i] == -1)
            cout << 1;
          else
            cout << e[i];
        } else {
          if (e[i] != -1)
            cout << e[i];
          else
            cout << 0;
        }
      }
    }
  }
}
