#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e18;
const long long MAX = 100001;
void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  while (m--) {
    int fst, snd;
    cin >> fst >> snd;
    int digit = (ans / pow(10, n - fst));
    digit = digit % 10;
    if (digit == snd) continue;
    if (digit == 0)
      ans += snd * pow(10, n - fst);
    else {
      cout << -1;
      return;
    }
  }
  if (ans < pow(10, n - 1))
    cout << "-1";
  else
    cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
