#include <bits/stdc++.h>
using namespace std;
bool fl[4];
int a[4];
int n, m, s, c;
int main() {
  cin >> n >> m;
  for (int i(1); i <= n; i++) a[i] = false;
  for (int i(1); i <= m; i++) {
    cin >> s >> c;
    if (fl[s]) {
      if (c != a[s]) {
        cout << -1;
        return 0;
      }
    } else {
      fl[s] = true;
      a[s] = c;
    }
  }
  if (a[1] == 0 && fl[1]) {
    cout << -1;
    return 0;
  }
  if (a[1] == 0) a[1] = 1;
  for (int i(1); i <= n; i++) cout << a[i];
}
