#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const long long MOD = (long long)1000000007;
const long long INF2 = (long long)100000000000000000;
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] == -1)
      a[s] = c;
    else if (a[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n == 1) {
    if (a[0] == -1) {
      cout << "0" << endl;
    } else {
      cout << a[0] << endl;
    }
    return 0;
  }
  if (a[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) a[i] = 0;
    cout << a[i];
  }
  cout << endl;
  return 0;
}
