#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
template <typename T>
T gcd(T x, T y) {
  if ((x == 1) || (y == 1)) return 1;
  if (x > y) {
    if (x % y == 0) {
      return y;
    } else {
      return gcd(y, x % y);
    }
  } else {
    if (y % x == 0) {
      return x;
    } else {
      return gcd(x, y % x);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vi a(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    int s;
    cin >> s;
    int c;
    cin >> c;
    if (a[s - 1] == -1 || a[s - 1] == c) {
      a[s - 1] = c;
    } else {
      cout << (-1) << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << (-1) << endl;
    return 0;
  } else if (a[0] == -1) {
    a[0] = 1;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] == -1) {
      cout << 0;
    } else {
      cout << a[i];
    }
  }
  cout << endl;
}
