#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} aaa;
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int n, m, k, w, h;
string s;
void Main() {
  char s;
  cin >> n >> m;
  string ans = "000";
  vector<bool> f(n, false);
  for (int i = int(0); i < int(m); ++i) {
    cin >> k >> s;
    k--;
    if (f[k] == 0) {
      ans[k] = s;
      f[k] = 1;
    } else {
      if (ans[k] == s)
        continue;
      else {
        cout << -1;
        return;
      }
    }
  }
  if (n > 1 && f[0] == true && ans[0] == '0') {
    ans = "-1";
    cout << ans;
    return;
  } else if (n > 1 && f[0] == false && ans[0] == '0')
    ans[3 - n] = 1;
  cout << stoi(ans);
}
signed main() {
  Main();
  return 0;
}
