#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int N, M;
int s[6], c[6];
string t = "000";
int num[4] = {-1, -1, -1};
int main() {
  cin >> N >> M;
  for (int i = (0); i < (M); i++) {
    cin >> s[i] >> c[i];
    if (num[s[i] - 1] == -1) {
      num[s[i] - 1] = c[i];
    } else {
      if (num[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (num[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  bool f = false;
  for (int i = (0); i < (N); i++) {
    if (num[i] >= 0) {
      if (!f) {
        if (num[i] == 0) {
          if (i > 0) {
            num[i - 1] = 1;
          }
        }
      }
      f = true;
    } else {
      if (f) {
        num[i] = 0;
      }
    }
  }
  for (int i = (0); i < (N); i++) {
    if (num[i] >= 0) {
      cout << num[i];
    }
  }
  cout << endl;
  return 0;
}
