#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, s[20005], c[2002];
  cin >> n >> m;
  for (long long int i = 0; i <= m - 1; i++) cin >> s[i] >> c[i];
  long long int chck = 0;
  long long int digi[n + 2];
  for (long long int i = 0; i <= n; i++) digi[i] = -1;
  for (long long int i = 0; i <= m - 1; i++) {
    if (digi[s[i]] == -1 || digi[s[i]] == c[i])
      digi[s[i]] = c[i];
    else
      chck++;
  }
  if (digi[1] == 0) chck++;
  if (chck)
    cout << -1;
  else {
    for (long long int i = 1; i <= n; i++)
      if (digi[i] == -1) digi[i] = 0;
    for (long long int i = 1; i <= n; i++) cout << digi[i];
  }
  return 0;
}
