#include <bits/stdc++.h>
using namespace std;
void test_case() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int a[n];
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; i++) {
    int index = s[i] - 1;
    if (a[index] == -1) {
      a[index] = c[i];
    } else {
      if (a[index] != c[i]) {
        cout << "-1";
        return;
      }
    }
  }
  for (int i = 0; i < m; i++)
    if (a[i] == -1) a[i] = 1;
  if (a[0] == 0 && n > 1) {
    cout << "-1";
    return;
  }
  for (int x : a) cout << x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  test_case();
}
