#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  bool can = true;
  for (int i = 0; i < M; i++) {
    int S, C;
    cin >> S >> C;
    if (S == 1 && C == 0) can = false;
    s[i] = S, c[i] = C + '0';
  }
  if (!can)
    cout << -1 << endl;
  else {
    string ans;
    for (int i = 0; i < pow(10, N); i++) {
      bool ok = true;
      string tmp = to_string(i);
      for (int j = 0; j < M; j++) {
        if (tmp[s[j] - 1] != c[j]) ok = false;
      }
      if (!ok)
        can = false;
      else {
        can = true;
        ans = tmp;
        break;
      }
    }
    cerr << ans << endl;
    if (!can)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
