#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
template <typename T>
void print(const T& v);
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<char> num(N, '0');
  vector<bool> seen(N, false);
  for (int i = 0; i < (int)(M); i++) {
    if (seen[s[i]] && (num[s[i]] != c[i])) {
      cout << -1 << endl;
      return 0;
    } else {
      num[s[i]] = c[i];
      seen[s[i]] = true;
    }
  }
  if (N != 1 && num[0] == '0' && seen[0]) {
    cout << -1 << endl;
    return 0;
  } else if (num[0] == '0') {
    num[0] = '1';
  }
  for (int i = 0; i < N; i++) {
    cout << num[i];
  }
  cout << endl;
  return 0;
}
template <typename T>
void print(T const& v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
