#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int a[3];
  for (int i = 0; i < n; ++i) a[i] = -1;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1) a[s] = c;
    if (a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (a[0] == -1) a[0] = 1;
  for (int i = 0; i < n; ++i)
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  cout << endl;
  return 0;
}
