#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e17;
long long gcd(long long a, long long b) {
  if (a == 0) return (b);
  return (gcd(b % a, a));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long arr[n];
  memset(arr, -1, sizeof(arr));
  long long c1, c2, flag = 0;
  ;
  while (m--) {
    cin >> c1 >> c2;
    cout << c1 << " " << c2 << endl;
    if (arr[c1 - 1] == -1)
      arr[c1 - 1] = c2;
    else if (arr[c1 - 1] != c2)
      flag = 1;
  }
  if (flag == 1)
    cout << -1 << endl;
  else {
    if (arr[0] == 0)
      cout << -1 << endl;
    else {
      long long m1 = 0;
      for (long long i = 0; i < n; i++) {
        if (arr[i] != -1) m1 += arr[i] * pow(10, n - i - 1);
      }
      cout << m1 << endl;
    }
  }
  return (0);
}
