#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int main() {
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = (0); i < (M); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> ans(N, -1);
  for (int i = (0); i < (M); ++i) {
    if (ans[s[i]] != -1 && ans[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i]] = c[i];
  }
  for (int i = (0); i < (N); ++i) {
    if (ans[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else if (ans[0] == -1) {
      cout << 1;
    } else if (ans[i] == -1) {
      cout << 0;
    } else {
      cout << ans[i];
    }
  }
  return 0;
}
