#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long LINF = 1e18;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i];
    cin >> c[i];
  }
  string ans = "0";
  for (int i = 0; i < (n - 1); i++) {
    ans = ans + '0';
  }
  bool check[n];
  for (int i = 0; i < (n); i++) {
    check[i] = false;
  }
  for (int i = 0; i < (m); i++) {
    if (ans[s[i] - 1] == '0' and !check[s[i] - 1]) {
      ans[s[i] - 1] = c[i] + '0';
      check[s[i] - 1] = true;
      continue;
    }
    if (ans[s[i] - 1] != c[i] + '0' and check[s[i] - 1]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (ans[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
}
