#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;
  string ans = string(n, '*');
  while (m--) {
    int fst, snd;
    cin >> fst >> snd;
    if (ans[fst - 1] == '*')
      ans[fst - 1] = snd + '0';
    else if (ans[fst - 1] == (snd + '0'))
      continue;
    else {
      cout << -1;
      return;
    }
  }
  for (int i = 0; i < n; i++)
    if (ans[i] == '*') ans[i] = '0';
  if (ans[0] == '0' && 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;
}
