#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < (M); ++i) cin >> s[i] >> c[i];
  int res[N];
  for (int i = 0; i < (N); ++i) res[i] = -1;
  for (int i = 0; i < (M); ++i) {
    int n = res[s[i] - 1];
    if (n == -1) {
      res[s[i] - 1] = c[i];
    } else {
      if (n != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  if (res[0] == -1) res[0] = 1;
  for (int i = 0; i < (N); ++i) {
    if (res[i] == -1)
      continue;
    else
      ans += res[i] * pow(10, N - 1 - i);
  }
  int len = to_string(ans).size();
  if (len != N) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
