#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX_N = int(1e6) + 10;
const long long int MOD = 1e9 + 7;
const long long int INF = 1e18;
inline long long int mul(long long int a, long long int b) {
  a = (a + MOD) % MOD;
  b = (b + MOD) % MOD;
  long long int c = a * b;
  c = (c + MOD) % MOD;
  return c;
}
inline long long int add(long long int a, long long int b) {
  a = (a + MOD) % MOD;
  b = (b + MOD) % MOD;
  long long int ans = (a + b);
  ans = (ans + MOD) % MOD;
  return ans;
}
long long int power(long long int a, long long int b, long long int c) {
  long long int ans = 1;
  while (b) {
    if (b & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
    b = b / 2;
  }
  return ans;
}
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P) {
  in >> P.first >> P.second;
  return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P) {
  out << "(" << P.first << ", " << P.second << ")";
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
template <class T>
istream &operator>>(istream &in, deque<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const deque<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
mt19937 rnd(time(0));
inline long long int gcd(long long int a, long long int b) {
  while (b) a %= b, swap(a, b);
  return a;
}
struct SOS {
  long long int *dp;
  int limit;
  vector<int> &arr;
  SOS(int _limit, vector<int> &v) : arr(v) {
    limit = _limit;
    dp = new long long int[(1 << limit) + 10];
  }
  void init() {
    for (int i = 0; i < (1 << limit); i++) {
      dp[i] = 0;
    }
    for (int i = 0; i < arr.size(); i++) {
      dp[arr[i]]++;
    }
  }
  void build1() {
    for (int i = 0; i < limit; i++) {
      for (int j = 0; j < (1 << limit); j++) {
        if (j & (1 << i)) {
          dp[j] = add(dp[j], dp[j ^ (1 << i)]);
        }
      }
    }
  }
  void build2() {
    for (int i = 0; i < limit; i++) {
      for (int j = (1 << limit) - 1; j >= 0; j--) {
        if (j & (1 << i)) {
          dp[j ^ (1 << i)] = add(dp[j ^ (1 << i)], dp[j]);
        }
      }
    }
  }
};
int find(int arr[], int x) {
  while (x != arr[x]) {
    x = arr[x];
  }
  return x;
}
void connect(int x, int arr[], int size[], int comp[], int y) {
  int rootA = find(arr, x);
  int rootB = find(arr, y);
  if (rootA == rootB) return;
  if (size[rootA] < size[rootB]) {
    arr[rootA] = rootB;
    size[rootB] += size[rootA];
    comp[rootB] = min(comp[rootA], comp[rootB]);
  } else {
    arr[rootB] = rootA;
    size[rootA] += size[rootB];
    comp[rootA] = min(comp[rootA], comp[rootB]);
  }
}
const int N = 2e5 + 5;
void update(int x, long long int tree[], long long int v) {
  while (x < 200005) {
    tree[x] += v;
    x += x & (-x);
  }
}
long long int q(int x, long long int tree[]) {
  long long int ans = 0;
  while (x) {
    ans += tree[x];
    x -= x & (-x);
  }
  return ans;
}
int digits(int x) {
  int c = 0;
  while (x) {
    c++;
    x = x / 10;
  }
  return c;
}
int sat(int x, vector<int> &v, vector<int> &v2) {
  vector<int> d;
  while (x) {
    d.push_back(x % 10);
    x = x / 10;
  }
  reverse(d.begin(), d.end());
  for (int i = 0; i < v.size(); i++) {
    if (d[v[i] - 1] != v2[i]) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v;
  vector<int> v2;
  for (int i = 1; i <= m; i++) {
    int c1, c2;
    cin >> c1 >> c2;
    v.push_back(c1);
    v2.push_back(c2);
  }
  for (int i = 1; i <= 1000; i++) {
    if (digits(i) == n && sat(i, v, v2)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1\n";
}
