#include <bits/stdc++.h>
using namespace std;
int a[100];
bool vis[100];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1, x1, x2; i <= m; i++) {
    cin >> x1 >> x2;
    if (!a[x1] && !vis[x1]) {
      a[x1] = x2;
      vis[x1]++;
    } else {
      if (a[x1] != x2) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  if (n == 1) {
    cout << a[1] << '\n';
    return 0;
  }
  if (!a[1])
    cout << -1 << '\n';
  else {
    for (int i = 1; i <= n; i++) {
      cout << a[i];
    }
  }
}
