#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
double pi = 3.1415926535;
int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m], y[3], x, c = 0, ans = 0;
  int d = 10;
  for (int i = 0; i < n - 1; i++) d *= 10;
  if (n == 1)
    x = 0;
  else
    x = d / 10;
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
  for (int i = x; i < d; i++) {
    y[0] = i / 100;
    y[1] = i % 10 / 10;
    y[2] = i % 10;
    for (int j = 0; j < m; j++) {
      if (y[a[j] - 1] == b[j]) c++;
    }
    if (c == m) {
      ans = i;
      break;
    }
    c = 0;
  }
  if (ans == 0)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
