#include <bits/stdc++.h>
using namespace std;
int a[3][3];
void check(int c) {}
void solve() {
  int n, m;
  int s[100], c[100];
  int num[5] = {0, 0, 0, 0, 0};
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 1; i <= m; i++) {
    if (num[s[i]] == 0)
      num[s[i]] = c[i];
    else {
      if (num[s[i]] != c[i]) {
        cout << "-1" << endl;
        return;
      }
    }
  }
  if (num[1] == 0 && n != 1) {
    cout << "-1" << endl;
    return;
  }
  for (int i = 1; i <= n; i++) {
    cout << num[i];
  }
  cout << endl;
  return;
}
int main() { solve(); }
