#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int a[20];
  int flag = 1;
  memset(a, 0, sizeof(a));
  a[1] = 1;
  bool vis[20];
  memset(vis, false, sizeof(vis));
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) flag = 0;
    if (vis[s] == false) {
      a[s] = c;
      vis[s] = true;
    } else if (a[s] != c)
      flag = 0;
  }
  if (flag == 0)
    cout << "-1";
  else
    for (int i = 1; i <= n; i++) cout << a[i];
  cout << endl;
}
