#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e17;
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];
  for (long long i = 0; i < n; i++) arr[i] = -1;
  long long c1, c2, flag = 0;
  while (m--) {
    cin >> c1 >> c2;
    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);
      }
      long long c = 0;
      for (long long i = m1; i != 0; i /= 10) c++;
      if (c != n) {
        m1 += pow(10, n - 1);
      }
      cout << m1 << endl;
    }
  }
  return (0);
}
